Пример #1
0
 /**
  * @param $path
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function delete($path)
 {
     return $this->tryReturn(function () use($path) {
         list($dir, $name) = FileSystem::splitNameFromPath($path);
         return $this->fileManager->in($dir)->deleteFile($name);
     });
 }
 /**
  * Set unique name for folder
  *
  * @param Folder $folder
  * @return Folder
  */
 public function folder(Folder $folder)
 {
     if (FileSystem::exists($folder->fullPath())) {
         $original_name = $folder->name();
         $folder->setName($original_name . '-1');
         for ($i = 2; FileSystem::exists($folder->fullPath()); $i++) {
             $folder->setName($original_name . '-' . $i);
         }
     }
     return $folder;
 }
Пример #3
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');
 }
Пример #4
0
 /**
  * Get url to folder content
  *
  * @param Path $path
  * @param null|string $name
  * @return string
  */
 public function forFolder(Path $path, $name = null)
 {
     $folder_path = FileSystem::join($path->relativePath(), $name);
     return action($this->dir_action, $this->pathToUrl($folder_path));
 }
 /**
  * @param Folder $folder
  *
  * @return bool
  *
  * @throws FileManagerException
  */
 public function deleteFolder(Folder $folder)
 {
     $path = $folder->fullPath();
     if (!FileSystem::exists($path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     if (!Perms::canDelete($path)) {
         throw new FileManagerException($this, 'err_folder_delete_perm');
     }
     return FileSystem::deleteDirectory($path);
 }
Пример #6
0
 /**
  * Set mime from file full path
  *
  * @param string $path
  * @return MimeService
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function setMimeByPath($path)
 {
     return $this->setMime(FileSystem::getMimeType($path));
 }
Пример #7
0
 /**
  * Get thumb File or folder full system path
  *
  * @param $size
  * @param File|null $file
  * @return string
  */
 public function thumbPath($size, File $file = null)
 {
     $thumb_path = [$this->sys_path, $this->thumbDirName(), Str::slug($size)];
     if (!is_null($file)) {
         $thumb_path[] = $file->fullName();
     }
     return FileSystem::join($thumb_path);
 }
Пример #8
0
 /**
  * Update folder details (use if name is changed)
  *
  * @returns $this
  * @throws FileManagerException
  */
 public function updateDetails()
 {
     $this->folder->dir = $this->url->pathToUrl($this->getPath()->relativePath());
     $this->folder->url = $this->url->forFolder($this->getPath(), $this->name());
     $this->folder->updated_at = date('Y-m-d H:i:s', stat($this->fullPath())['mtime']);
     $this->folder->bytes = FileSystem::dirSize($this->fullPath(), [$this->getPath()->thumbDirName()]);
     return $this;
 }
Пример #9
0
 /**
  * Delete file thumbs from filesystem
  *
  * @param File $file
  * @throws \Crip\FileManager\Exceptions\FileManagerException
  */
 public function delete(File $file)
 {
     collect(array_keys($this->sizes))->each(function ($size) use($file) {
         $path = $file->getPath()->thumbPath($size, $file);
         if (FileSystem::exists($path)) {
             FileSystem::delete($path);
         }
     });
 }
Пример #10
0
 /**
  * Add folder to parent directory
  */
 private function addFolderBack()
 {
     $parts = collect(FileSystem::split($this->getPath()->relativePath()));
     $parts->pop();
     $patent_path = app(Path::class)->change($parts->implode(DIRECTORY_SEPARATOR));
     $folder = app(Folder::class)->setPath($patent_path)->setName('..')->updateDetails();
     $this->content->push($folder->details());
 }