|
...
|
...
|
@@ -318,34 +318,37 @@ class ImageController extends Controller |
|
|
|
private function multi(&$files) {
|
|
|
|
$data = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$hash = hash_file('sha256', $file->getPathname());
|
|
|
|
$name = $file->getClientOriginalName();
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
//查看图片是否已上传
|
|
|
|
$param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0,'is_cos'=>(($this->upload_location == 0) ? 1 : 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'],$image_hash['name']);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$image_type = $file->getClientOriginalExtension();
|
|
|
|
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
|
|
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
$amazonS3Service->uploadFiles($file,$this->path,$fileName);
|
|
|
|
try {
|
|
|
|
$hash = hash_file('sha256', $file->getPathname());
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
//查看图片是否已上传
|
|
|
|
$param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0,'is_cos'=>(($this->upload_location == 0) ? 1 : 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'],$image_hash['name']);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$name = $file->getClientOriginalName();
|
|
|
|
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
|
|
$image_type = $file->getClientOriginalExtension();
|
|
|
|
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
$amazonS3Service->uploadFiles($file,$this->path,$fileName);
|
|
|
|
}
|
|
|
|
$this->synchronizationImage($fileName,$this->upload_location);
|
|
|
|
$data[] = $this->responseData($this->path.'/'.$fileName,$name);
|
|
|
|
}catch (\Exception $e){
|
|
|
|
$this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
$this->synchronizationImage($fileName,$this->upload_location);
|
|
|
|
$data[] = $this->responseData($this->path.'/'.$fileName,$name);
|
|
|
|
$hash = $name = '';
|
|
|
|
}
|
|
|
|
$this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
}
|
...
|
...
|
|