Example #1
0
 public static function checkDirPermission()
 {
     $dirPath = storage_path('app/' . self::$dir);
     if (!Filesystem::exists($dirPath)) {
         Filesystem::makeDirectory($dirPath, 0774);
     }
 }
Example #2
0
 public function setImageAttribute($value)
 {
     if ($this->image) {
         $this->image->delete();
     }
     if (!is_null($value)) {
         $imageName = last(explode('/', $value));
         $targetDirectory = config('admin.imagesUploadDirectory') . '/slides';
         $toDirectory = public_path($targetDirectory);
         if (!\File::exists($toDirectory)) {
             \File::makeDirectory($toDirectory);
         }
         if (\File::exists($value)) {
             \File::move(public_path($value), $toDirectory . '/' . $imageName);
         }
         $this->attributes['image'] = $targetDirectory . '/' . $imageName;
     }
 }
Example #3
0
 public static function storeCMPicture($img_url)
 {
     // post save
     $post = \App\Post::create(array('user_id' => \Auth::user()->id, 'content' => ''));
     $post->postGroups()->attach(\Auth::user()->postGroups()->first()->id);
     // photo save
     $types = array('_s.', '_m.', '_l.');
     $sizes = array(100, 300, 600);
     $original_file_name = $img_url;
     $file_ext = 'jpg';
     $target_path = base_path() . '/public/imgs/';
     $hashSeed = "post" . $post->id . $original_file_name;
     while (1) {
         $file_name = \Func::getHashedValue($hashSeed);
         if (!\File::exists($target_path . \Func::getImgPath($file_name))) {
             break;
         }
         $hashSeed .= rand();
     }
     $target_path .= \Func::getImgPath($file_name) . '/';
     if (!\File::exists($target_path)) {
         \File::makeDirectory($target_path, 0775, true);
     }
     foreach ($types as $key => $type) {
         $new_name = $file_name . $type . $file_ext;
         $img = \Image::make($img_url);
         $img->resize($sizes[$key], null, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save($target_path . $new_name);
         $img->destroy();
     }
     \App\Photo::create(array('post_id' => $post->id, 'sequence' => 1, 'img_path' => $file_name . '.' . $file_ext));
 }
Example #4
0
 /**
  * get relative url for local rep photos
  * @param  Representative $rep
  * @return string      relative url
  */
 public function setPhoto()
 {
     if (isset($this->photo)) {
         return;
     }
     $dir = '/images/reps/';
     $ext = '.jpg';
     if (isset($this->name)) {
         $pieces = explode(" ", $this->name);
         if (count($pieces) < 2) {
             return;
         }
         $first = array_shift($pieces);
         array_push($pieces, $first);
         $filename = $dir . implode("-", $pieces) . $ext;
         if (\File::exists(public_path() . $filename)) {
             $this->photo = $filename;
         }
     }
 }
Example #5
0
 /**
  * Get image mime type
  * @return string
  */
 public function getMime()
 {
     $filePath = $this->getPath();
     if (\File::exists($filePath)) {
         return \File::mimeType($filePath);
     }
     return 'unknown/unknown';
 }