|
...
|
...
|
@@ -166,10 +166,7 @@ class ImageController extends Controller |
|
|
|
if ($type == 'multi') {
|
|
|
|
return $this->multi($files);
|
|
|
|
}else{
|
|
|
|
$size = $files->getSize();
|
|
|
|
$image_type = $files->getClientOriginalExtension();
|
|
|
|
$mime = $files->getMimeType();
|
|
|
|
return $this->single($files,$size,$image_type,$mime);
|
|
|
|
return $this->single($files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -181,14 +178,23 @@ class ImageController extends Controller |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/17 16:30
|
|
|
|
*/
|
|
|
|
public function single(&$files,$size,$image_type,$mime){
|
|
|
|
public function single(&$files){
|
|
|
|
$size = $files->getSize();
|
|
|
|
$image_type = $files->getClientOriginalExtension();
|
|
|
|
$mime = $files->getMimeType();
|
|
|
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
//查看文件是否存在
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
|
|
|
|
//查看图片是否已上传
|
|
|
|
$param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
|
|
|
|
if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
|
|
|
|
$param['project_id'] = $this->cache['project_id'];
|
|
|
|
}
|
|
|
|
$image_hash = $imageModel->read($param);
|
|
|
|
if($image_hash !== false){
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
|
|
|
|
}
|
|
|
|
//保存路径
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
|
|
//上传到cos
|
|
...
|
...
|
@@ -196,10 +202,7 @@ class ImageController extends Controller |
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$files->move($url,$fileName);
|
|
|
|
}
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
|
|
...
|
...
|
@@ -230,10 +233,8 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $info
|
|
|
|
* @param $w
|
|
|
|
* @param $h
|
|
|
|
* @remark :生成缩略图
|
|
|
|
* @name :cacheImage
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -248,7 +249,6 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $files
|
|
|
|
* @remark :多图片上传
|
|
|
|
* @name :multi
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -263,7 +263,12 @@ class ImageController extends Controller |
|
|
|
$mime = $file->getMimeType();
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
|
|
|
|
//查看图片是否已上传
|
|
|
|
$param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
|
|
|
|
if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
|
|
|
|
$param['project_id'] = $this->cache['project_id'];
|
|
|
|
}
|
|
|
|
$image_hash = $imageModel->read($param);
|
|
|
|
if($image_hash !== false){
|
|
|
|
$data[] = $this->responseData($image_hash['path']);
|
|
|
|
continue;
|
|
...
|
...
|
@@ -275,10 +280,7 @@ class ImageController extends Controller |
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$res = $file->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
$this->response($file->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$file->move($url,$fileName);
|
|
|
|
}
|
|
|
|
//批量存储
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|
...
|
...
|
|