VideoUpload.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Widget\Tools;
  3. use Illuminate\Support\Facades\Request;
  4. use Intervention\Image\Facades\Image;
  5. //use FFMpeg;
  6. /**
  7. * Created by PhpStorm.
  8. * User: steven
  9. * Date: 16/9/12
  10. * Time: 下午8:06
  11. */
  12. class VideoUpload
  13. {
  14. protected static function mkFolder($path)
  15. {
  16. if (!is_readable($path)) {
  17. mkdir($path, 0700, true);
  18. }
  19. }
  20. /*
  21. * 文件存储工具
  22. *
  23. */
  24. public static function mvFile($fileName, $sizex = 150, $sizey = 200,$isImage = false, $dir = 'order')//200 270
  25. {
  26. if (!Request::hasFile($fileName)) return false;
  27. $file = Request::file($fileName);
  28. VideoUpload::mkFolder(public_path('upload/'));
  29. if(Request::get('article_id'))$dir=Request::get('article_id');
  30. $filePath = public_path('upload/'.$dir.'/');
  31. VideoUpload::mkFolder($filePath);
  32. $fileName = time() . '.' . $file->getClientOriginalExtension();
  33. // $fileName = $clientName . '.' . $file->getClientOriginalExtension();
  34. \Log::info($filePath. $fileName);
  35. if($isImage){
  36. if (!Image::make($file)->resize($sizex, $sizey)->save($filePath. $fileName)) return false;
  37. }else{
  38. $file->move($filePath, $fileName);
  39. /* //正常缩略图
  40. $ffmpeg = FFMpeg\FFMpeg::create(array(
  41. 'ffmpeg.binaries' => '/usr/bin/ffmpeg',
  42. 'ffprobe.binaries' => '/usr/bin/ffprobe'
  43. ));
  44. $video = $ffmpeg->open($filePath. $fileName);
  45. $vpath = $filePath;
  46. if (!file_exists($vpath)) {
  47. if (!@mkdir($vpath, 0755, true)) {
  48. return ErrorCode::ATTACHMENT_MKDIR_FAILED;
  49. }
  50. }
  51. $pic = $vpath. $fileName.'.jpg';
  52. \Log::info($pic);
  53. $video
  54. ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1))
  55. ->save( $pic );*/
  56. }
  57. return '/upload/' .$dir.'/'. $fileName;
  58. }
  59. }