public function postUpload()
 {
     $file = Input::all();
     $dir = Auth::user()->username;
     $path = '/users/' . $dir;
     if (!is_dir(public_path() . $path)) {
         mkdir(public_path() . $path);
     }
     $name = MaterialFileController::sanitize(pathinfo($file['file']->getClientOriginalName(), PATHINFO_FILENAME));
     $extension = strtolower($file['file']->getClientOriginalExtension());
     $filename = $name . '.' . $extension;
     $file['file']->move(public_path() . $path . '/', $filename);
     $response = $filename;
     return $response;
 }
 public function destroy(Material $material, $id)
 {
     $material = Material::findOrFail($id);
     if (count($material->files) > 0) {
         foreach ($material->files as $file) {
             MaterialFileController::destroyFile($file->filename);
             $thumb = 'thumbs/' . pathinfo($file->filename, PATHINFO_FILENAME) . '.jpg';
             MaterialFileController::destroyFile($thumb);
         }
     }
     $material->delete();
     Session::flash('success', $material->slug . ' successfully deleted!');
     return redirect()->action('Admin\\UserController@home');
 }
Пример #3
0
 public static function makeThumb($extension, $filename)
 {
     switch ($extension) {
         case 'pdf':
         case 'PDF':
             $name = pathinfo($filename, PATHINFO_FILENAME);
             $pdf = new Spatie\PdfToImage\Pdf(storage_path('app/' . $filename));
             $old_path = storage_path() . '/app/' . $name . '.jpg';
             $pdf->saveImage($old_path);
             MaterialFile::resize($name . '.jpg');
             $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg';
             if (File::move($old_path, $new_path)) {
                 $pathToPicture = '/thumbs';
                 break;
             } else {
                 $pathToPicture = "failed to copy {$filename}...\n";
                 break;
             }
             break;
         case 'doc':
         case 'DOC':
         case 'docx':
         case 'DOCX':
         case 'ppt':
         case 'PPT':
         case 'pptx':
         case 'PPTX':
             $path = storage_path() . '/app/';
             chdir($path);
             exec("export HOME=/tmp && libreoffice --headless --convert-to pdf {$filename}");
             $name = pathinfo($filename, PATHINFO_FILENAME);
             $pdf = new Spatie\PdfToImage\Pdf(storage_path('app/' . $name . '.pdf'));
             $old_path = $name . '.jpg';
             $pdf->saveImage($old_path);
             MaterialFile::resize($old_path);
             $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg';
             if (File::move($old_path, $new_path)) {
                 $pathToPicture = '/thumbs';
                 $pdf = $name . '.pdf';
                 MaterialFileController::destroyFile($pdf);
                 break;
             } else {
                 $pathToPicture = "failed to copy {$filename}...\n";
                 break;
             }
             break;
         case 'jpg':
         case 'JPG':
         case 'png':
         case 'PNG':
         case 'bmp':
             MaterialFile::resize($filename);
             $new_path = storage_path() . '/app/thumbs/' . $filename;
             if (File::move($filename, $new_path)) {
                 $pathToPicture = '/thumbs';
                 break;
             } else {
                 $pathToPicture = "failed to copy {$filename}...\n";
                 break;
             }
             break;
         case 'mp3':
         case 'MP3':
             $name = pathinfo($filename, PATHINFO_FILENAME);
             $old_path = 'img/audio.png';
             $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg';
             if (File::move($old_path, $new_path)) {
                 $pathToPicture = '/thumbs';
                 break;
             } else {
                 $pathToPicture = "failed to copy {$filename}...\n";
                 break;
             }
             break;
         case 'WMV':
         case 'wmv':
         case 'mp4':
         case 'MP4':
         case 'avi':
         case 'AVI':
         case 'mov':
         case 'MOV':
             $path = storage_path() . '/app/';
             chdir($path);
             $name = pathinfo($filename, PATHINFO_FILENAME);
             exec("ffmpeg -i {$filename} -ss 1 -vframes 1 {$name}.jpg");
             $old_path = $name . '.jpg';
             MaterialFile::resize($old_path);
             $new_path = storage_path() . '/app/thumbs/' . $name . '.jpg';
             if (File::move($old_path, $new_path)) {
                 $pathToPicture = '/thumbs';
                 break;
             } else {
                 $pathToPicture = "failed to copy {$filename}...\n";
                 break;
             }
             break;
         default:
             $pathToPicture = 'img/file-icon.png';
             break;
     }
     return $pathToPicture;
 }