Exemplo n.º 1
0
 /**
  * @param UploadedFile $uploaded_file
  * @return array Uploaded file info
  * @throws FileManagerException
  */
 public function upload(UploadedFile $uploaded_file)
 {
     if ($uploaded_file->isValid()) {
         $file = $this->file->uploading($uploaded_file);
         $this->uniqueName->file($file);
         $uploaded_file->move($file->dirPath(), $file->fullName());
         if ($file->isImage()) {
             $this->thumb->create($file);
             $file->setFileThumb();
         }
         return (array) $file->details();
     }
     throw new FileManagerException($this, 'err_file_upload_invalid_file');
 }
 /**
  * @param Folder $folder
  * @param string $name
  * @return Folder
  * @throws FileManagerException
  */
 public function renameFolder(Folder $folder, $name)
 {
     $old_folder_path = $folder->fullPath();
     $new_folder = app(Folder::class)->setPath($folder->getPath())->setName($name);
     $new_folder_path = $new_folder->fullPath();
     if (!FileSystem::exists($old_folder_path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     // if old name is the same as new one, just return existing folder info
     if ($old_folder_path === $new_folder_path) {
         return $folder;
     }
     if (FileSystem::exists($new_folder_path)) {
         $new = $this->uniqueName->folder($new_folder);
     }
     if (rename($old_folder_path, $new_folder->fullPath())) {
         return $new_folder->updateDetails()->details();
     }
     throw new FileManagerException($this, 'err_folder_cant_rename');
 }