|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
+use Acekyd\LaravelMP3\LaravelMP3;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Storage;
|
|
@@ -58,6 +59,8 @@ class UploadController extends Controller
|
|
$height = Image::make($filePath)->height();
|
|
$height = Image::make($filePath)->height();
|
|
//要保存的文件名 时间+扩展名
|
|
//要保存的文件名 时间+扩展名
|
|
$filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
|
|
$filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
|
|
|
|
+ //todo 等待客户端更新后替换为下列规则
|
|
|
|
+ //$filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
|
|
} else {
|
|
} else {
|
|
//要保存的文件名 时间+扩展名
|
|
//要保存的文件名 时间+扩展名
|
|
$filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
$filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
@@ -78,4 +81,33 @@ class UploadController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function uploadMp3(Request $request)
|
|
|
|
+ {
|
|
|
|
+ if ($request->hasFile('mp3') && $request->file('mp3')->isValid()) {
|
|
|
|
+ $path = 'music' . '/';
|
|
|
|
+ //获取文件的扩展名
|
|
|
|
+ $kuoname = $request->file('mp3')->getClientOriginalExtension();
|
|
|
|
+
|
|
|
|
+ //获取文件的绝对路径,但是获取到的在本地不能打开
|
|
|
|
+ $filePath = $request->file('mp3')->getRealPath();
|
|
|
|
+ //计算音乐时长
|
|
|
|
+ $laravel_mp3 = new LaravelMP3();
|
|
|
|
+ $details = $laravel_mp3->getDuration($filePath);
|
|
|
|
+ Log::debug('文件类型'.$kuoname);
|
|
|
|
+ //要保存的文件名 时间+扩展名
|
|
|
|
+ $filename = time() . '_' . uniqid() . '*' . $kuoname;
|
|
|
|
+
|
|
|
|
+ $mp3Url = Storage::put($path . $filename, file_get_contents($filePath));
|
|
|
|
+ Log::debug('upload_url:' . $mp3Url);
|
|
|
|
+ if ($mp3Url) {
|
|
|
|
+ $data = ['url' => config('customer.chxq_oss_url') . $path . $filename,'music_duration' => $details];
|
|
|
|
+ return $data;
|
|
|
|
+ } else {
|
|
|
|
+ return 'mp3上传失败,请重试';
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return '仅支持mp3上传,请重试';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|