作者 lyh

gx

... ... @@ -79,13 +79,13 @@ class FileController
* @time :2023/6/17 16:32
*/
public function upload() {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(1111, true) . PHP_EOL, FILE_APPEND);
$this->request->validate([
'file'=>['required'],
],[
'file.required'=>'必须填写',
]);
$files = $this->request->file('file');
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('进入111', true) . PHP_EOL, FILE_APPEND);
if (empty($files)) {
$this->response('没有上传的文件!');
}
... ... @@ -94,7 +94,6 @@ class FileController
if ($type == 'multi') {
return $this->multi($files);
} else {
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('进入333', true) . PHP_EOL, FILE_APPEND);
return $this->single($files);
}
}
... ... @@ -107,7 +106,6 @@ class FileController
* @time :2023/6/17 16:32
*/
public function single(&$files){
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(111, true) . PHP_EOL, FILE_APPEND);
$hash = hash_file('md5', $files->getPathname());
$name = $files->getClientOriginalName();
//查看文件是否存在
... ... @@ -124,7 +122,6 @@ class FileController
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
//同步数据到cos
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(222222, true) . PHP_EOL, FILE_APPEND);
if($this->upload_location == 1){
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
... ... @@ -134,7 +131,6 @@ class FileController
return $this->response($files->getError(), Code::USER_ERROR);
}
}
@file_put_contents(storage_path('logs/lyh_error.log'), var_export(333, true) . PHP_EOL, FILE_APPEND);
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
$this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
}
... ...