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' ];