From e0e34aef56627f28a0b18df15fc369b57d6986f4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 4 Dec 2023 10:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/api/controller/IndexController.php | 12 +++++++++--- config/plugin/mongdch/webman-uploadslice/app.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ea50650..ed0a3cf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .env /tests/tmp /tests/.phpunit.result.cache +public \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index bebd9d3..b2b3db3 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,9 +44,14 @@ class IndexController extends BaseController{ } public function upload(Request $request){ - return json(['code' => 0, 'msg' => 'upload faild']); + $file = $request->file('file'); + if ($file) { + $time=time(); + $file->move(public_path() . DIRECTORY_SEPARATOR . 'uploads/file/'.date('Y-m-d').'/'.$time.'.'.$file->getUploadExtension()); + return json(['code' => 0, 'msg' => 'upload success','data'=>Env('URL').'/uploads/file/'.date('Y-m-d').'/'.$time.'.'. $file->getUploadExtension()]); + } + return json(['code' => 1, 'msg' => 'file not found']); - $data = $request->post(); // 验证数据 $validate = new Validate(); $check = $validate->data($data)->rule([ @@ -84,7 +89,8 @@ class IndexController extends BaseController{ // 合并 $mergeInfo = $sdk->merge($data['uuid'], $data['chunkLength'], $data['filename']); // $mergeInfo = $sdk->merge($data['uuid'], $data['chunkLength'], $data['filename'], 'dirname'); - // return json(['code' => 1, 'msg' => 'ok', 'data' =>Env('URL'). $mergeInfo]); + // return json(['code' => 1, 'msg' => 'ok', 'data' =>$mergeInfo]); + return json(['code' => 1, 'msg' => 'ok', 'data' =>Env('URL').'/uploads/'.date('Y-m-d').'/'. $mergeInfo['fileName']]); } catch (UploadException $e) { return json(['code' => 0, 'msg' => $e->getMessage()]); } diff --git a/config/plugin/mongdch/webman-uploadslice/app.php b/config/plugin/mongdch/webman-uploadslice/app.php index 5efbf83..c72c2cf 100644 --- a/config/plugin/mongdch/webman-uploadslice/app.php +++ b/config/plugin/mongdch/webman-uploadslice/app.php @@ -8,7 +8,7 @@ return [ // 分片文件大小限制 'sliceSize' => 0, // 保存根路径 - 'rootPath' => public_path() . DIRECTORY_SEPARATOR . 'upload', + 'rootPath' => public_path() . DIRECTORY_SEPARATOR . 'uploads/file/'.date('Y-m-d'), // 临时文件存储路径,基于rootPath 'tmpPath' => 'tmp' ];