This commit is contained in:
mkm 2023-12-04 10:55:57 +08:00
parent b51f7f01df
commit e0e34aef56
3 changed files with 11 additions and 4 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
.env
/tests/tmp
/tests/.phpunit.result.cache
public

View File

@ -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()]);
}

View File

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