コード例 #1
0
 public static function removeFile($id)
 {
     $file = MaterialFile::findorfail($id);
     $material = $file->materials;
     MaterialFileController::destroyFile($file->filename);
     $thumb = 'thumbs/' . pathinfo($file->filename, PATHINFO_FILENAME) . '.jpg';
     MaterialFileController::destroyFile($thumb);
     $file->delete($id);
     Session::flash('warning', 'You have successfully deleted' . $file->filename);
     return redirect()->back()->with('material', 'material');
 }
コード例 #2
0
 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;
 }