12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Widget\Tools;
- use App\Models\BaseAttachmentModel;
- use Illuminate\Support\Facades\Request;
- use Intervention\Image\Facades\Image;
- use Symfony\Component\HttpFoundation\File\Exception\FileException;
- //use FFMpeg;
- /**
- * Created by PhpStorm.
- * User: steven
- * Date: 16/9/12
- * Time: 下午8:06
- */
- class VideoUpload
- {
- protected static function mkFolder($path)
- {
- if (!is_readable($path)) {
- mkdir($path, 0700, true);
- }
- }
- /*
- * 文件存储工具
- *
- */
- public static function mvFile($fileName)
- {
- $rel_path = '/upload/video/' . date('Ymd');
- $path = public_path() . $rel_path;
- if (!Request::hasFile($fileName)) return false;
- $file = Request::file($fileName);
- $fileSize = $file->getSize();
- $clientName = $file->getClientOriginalName();
- $md5 = md5($clientName . time());
- $md5_filename = $md5 . '.' . $file->getClientOriginalExtension();
- $fileMimeType = $file->getMimeType();
- try {
- if(!$file->move($path, $md5_filename)){
- return false;
- }
- $real_path = $path . '/' . $md5_filename;
- $url_path = $rel_path . '/' . $md5_filename;
- $attachment = new BaseAttachmentModel();
- $attachment->name = $clientName;
- $attachment->md5 = $md5;
- $attachment->path = $real_path;
- $attachment->url = $url_path;
- $attachment->size = $fileSize;
- $attachment->file_type = $fileMimeType;
- if ($attachment->save()) {
- return env('APP_URL').'/attachment/'.$md5;
- } else {
- @unlink($real_path);
- return false;
- }
- } catch (FileException $e) {
- return false;
- }
- }
- }
|