Пример #1
0
 /**
  * Create thumbs for file
  *
  * @param File $file
  * @return array
  * @throws \Crip\FileManager\Exceptions\FileManagerException
  */
 public function create(File $file)
 {
     foreach ($this->sizes as $size_key => $size) {
         $img = app(ImageManager::class)->make($file->fullPath());
         $new_path = $file->getPath()->thumbPath($size_key);
         FileSystem::mkdir($new_path, 777, true);
         switch ($size[2]) {
             case 'width':
                 // resize the image to a width of $sizes[ 0 ] and constrain aspect ratio (auto height)
                 $img->resize($size[0], null, function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 break;
             case 'height':
                 // resize the image to a height of $sizes[ 1 ] and constrain aspect ratio (auto width)
                 $img->resize(null, $size[1], function ($constraint) {
                     $constraint->aspectRatio();
                 });
                 break;
                 // 'resize'
             // 'resize'
             default:
                 $img->fit($size[0], $size[1]);
                 break;
         }
         $img->save($file->getPath()->thumbPath($size_key, $file));
     }
     return $this->details($file);
 }
 /**
  * @param File $file
  *
  * @return bool
  *
  * @throws FileManagerException
  */
 public function deleteFile(File $file)
 {
     $path = $file->fullPath();
     if (!FileSystem::exists($path)) {
         throw new FileManagerException($this, 'err_file_not_found');
     }
     if (!Perms::canDelete($path)) {
         throw new FileManagerException($this, 'err_file_delete_perm');
     }
     if (FileSystem::delete($path)) {
         if ($file->isImage()) {
             $this->thumb->delete($file);
         }
         return true;
     }
     return false;
 }
 /**
  * Set unique name for file
  *
  * @param File $file
  * @return File
  */
 public function file(File $file)
 {
     if (FileSystem::exists($file->fullPath())) {
         $original_name = $file->name();
         $file->setName($original_name . '-1');
         for ($i = 2; FileSystem::exists($file->fullPath()); $i++) {
             $file->setName($original_name . '-' . $i);
         }
     }
     return $file;
 }
Пример #4
0
 /**
  * Get file content
  *
  * @param string|null $size
  * @return string
  * @throws FileManagerException
  */
 public function content($size = null)
 {
     $file_path = $this->fullPath();
     if ($size and array_key_exists($size, $this->thumb->getSizes())) {
         $thumb_path = $this->getPath()->thumbPath($size, $this);
         if (FileSystem::exists($thumb_path)) {
             $file_path = $thumb_path;
         }
     }
     if (FileSystem::exists($file_path)) {
         return LaravelFile::get($file_path);
     }
     throw new FileManagerException($this, 'err_file_not_found');
 }
Пример #5
0
 /**
  * Update file when path manager is set up
  *
  * @param Path $path
  */
 protected function onPathUpdate(Path $path)
 {
     $this->file->setPath($path);
     $this->thumb->setPath($path);
 }
Пример #6
0
 /**
  * Delete file from file system
  *
  * @param string $name File name to be deleted
  * @return bool Is file deleted
  */
 public function deleteFile($name)
 {
     $file = $this->file->existing($name);
     return $this->sys->deleteFile($file);
 }