Example #1
0
 public function uploadPost(Request $request, Folder $folder)
 {
     $this->authorize('all', $folder);
     $file = $request->file('file');
     if (!$file) {
         fmsgs(['title' => 'No File Detected', 'type' => 'error', 'text' => 'Please provide the file you want to upload!']);
         return redirect()->back();
     }
     $extension = $file->getClientOriginalExtension();
     if (!$file->isValid()) {
         fmsgs(['title' => 'File is not Valid', 'type' => 'error', 'text' => $file->getErrorMessage()]);
         return redirect()->back();
     }
     $filename = $file->getFilename() . '.' . $extension;
     $name = $file->getClientOriginalName();
     $storage = Storage::disk('local')->put($filename, file_get_contents($file->getRealPath()));
     $file = FileModel::create(['name' => $name, 'filename' => $filename, 'folder_id' => $folder->id]);
     if (explode('/', fileInfo($file)['type'])[0] === 'image' && explode('/', mimeTypeFromString($extension))[0] === 'image') {
         $this->createOptimizedImage($filename);
     }
     if ($this->user->auto_share) {
         $this->_share($file, 1, true, false);
     }
     fmsgs(['title' => 'File Uploaded', 'type' => 'success', 'text' => 'The file uploaded successfully']);
     return redirect('/files/' . $folder->id);
 }