作者 lyh

gx

... ... @@ -179,9 +179,6 @@ class ImageController extends Controller
* @time :2023/6/17 16:30
*/
public function single(&$files){
$size = $files->getSize();
$image_type = $files->getClientOriginalExtension();
$mime = $files->getMimeType();
$hash = hash_file('md5', $files->getPathname());
//查看文件是否存在
$imageModel = new ImageModel();
... ... @@ -196,6 +193,7 @@ class ImageController extends Controller
}
//保存路径
$url = $this->config['root'].$this->path;
$image_type = $files->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
//上传到cos
if($this->upload_location == 1){
... ... @@ -204,7 +202,7 @@ class ImageController extends Controller
}else{
$files->move($url,$fileName);
}
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType());
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
}
... ... @@ -258,9 +256,6 @@ class ImageController extends Controller
private function multi(&$files) {
$data = [];
foreach ($files as $file) {
$size = $file->getSize();
$image_type = $file->getClientOriginalExtension();
$mime = $file->getMimeType();
$imageModel = new ImageModel();
$hash = hash_file('md5', $file->getPathname());
//查看图片是否已上传
... ... @@ -274,7 +269,8 @@ class ImageController extends Controller
continue;
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension();
$image_type = $file->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
... ... @@ -283,7 +279,7 @@ class ImageController extends Controller
$file->move($url,$fileName);
}
//批量存储
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType());
$data[] = $this->responseData($this->path.'/'.$fileName);
}
$this->response('图片资源',Code::SUCCESS,$data);
... ...