|
@@ -166,10 +166,7 @@ class ImageController extends Controller |
|
@@ -166,10 +166,7 @@ class ImageController extends Controller |
|
166
|
if ($type == 'multi') {
|
166
|
if ($type == 'multi') {
|
|
167
|
return $this->multi($files);
|
167
|
return $this->multi($files);
|
|
168
|
}else{
|
168
|
}else{
|
|
169
|
- $size = $files->getSize();
|
|
|
|
170
|
- $image_type = $files->getClientOriginalExtension();
|
|
|
|
171
|
- $mime = $files->getMimeType();
|
|
|
|
172
|
- return $this->single($files,$size,$image_type,$mime);
|
169
|
+ return $this->single($files);
|
|
173
|
}
|
170
|
}
|
|
174
|
}
|
171
|
}
|
|
175
|
|
172
|
|
|
@@ -181,14 +178,23 @@ class ImageController extends Controller |
|
@@ -181,14 +178,23 @@ class ImageController extends Controller |
|
181
|
* @method :post
|
178
|
* @method :post
|
|
182
|
* @time :2023/6/17 16:30
|
179
|
* @time :2023/6/17 16:30
|
|
183
|
*/
|
180
|
*/
|
|
184
|
- public function single(&$files,$size,$image_type,$mime){
|
181
|
+ public function single(&$files){
|
|
|
|
182
|
+ $size = $files->getSize();
|
|
|
|
183
|
+ $image_type = $files->getClientOriginalExtension();
|
|
|
|
184
|
+ $mime = $files->getMimeType();
|
|
185
|
$hash = hash_file('md5', $files->getPathname());
|
185
|
$hash = hash_file('md5', $files->getPathname());
|
|
186
|
//查看文件是否存在
|
186
|
//查看文件是否存在
|
|
187
|
$imageModel = new ImageModel();
|
187
|
$imageModel = new ImageModel();
|
|
188
|
- $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
|
188
|
+ //查看图片是否已上传
|
|
|
|
189
|
+ $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
|
|
|
|
190
|
+ if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
|
|
|
|
191
|
+ $param['project_id'] = $this->cache['project_id'];
|
|
|
|
192
|
+ }
|
|
|
|
193
|
+ $image_hash = $imageModel->read($param);
|
|
189
|
if($image_hash !== false){
|
194
|
if($image_hash !== false){
|
|
190
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
|
195
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
|
|
191
|
}
|
196
|
}
|
|
|
|
197
|
+ //保存路径
|
|
192
|
$url = $this->config['root'].$this->path;
|
198
|
$url = $this->config['root'].$this->path;
|
|
193
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
199
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
194
|
//上传到cos
|
200
|
//上传到cos
|
|
@@ -196,10 +202,7 @@ class ImageController extends Controller |
|
@@ -196,10 +202,7 @@ class ImageController extends Controller |
|
196
|
$cosService = new CosService();
|
202
|
$cosService = new CosService();
|
|
197
|
$cosService->uploadFile($files,$this->path,$fileName);
|
203
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
198
|
}else{
|
204
|
}else{
|
|
199
|
- $res = $files->move($url,$fileName);
|
|
|
|
200
|
- if ($res === false) {
|
|
|
|
201
|
- return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
202
|
- }
|
205
|
+ $files->move($url,$fileName);
|
|
203
|
}
|
206
|
}
|
|
204
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|
207
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|
|
205
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
|
208
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
|
|
@@ -230,10 +233,8 @@ class ImageController extends Controller |
|
@@ -230,10 +233,8 @@ class ImageController extends Controller |
|
230
|
}
|
233
|
}
|
|
231
|
return true;
|
234
|
return true;
|
|
232
|
}
|
235
|
}
|
|
|
|
236
|
+
|
|
233
|
/**
|
237
|
/**
|
|
234
|
- * @param $info
|
|
|
|
235
|
- * @param $w
|
|
|
|
236
|
- * @param $h
|
|
|
|
237
|
* @remark :生成缩略图
|
238
|
* @remark :生成缩略图
|
|
238
|
* @name :cacheImage
|
239
|
* @name :cacheImage
|
|
239
|
* @author :lyh
|
240
|
* @author :lyh
|
|
@@ -248,7 +249,6 @@ class ImageController extends Controller |
|
@@ -248,7 +249,6 @@ class ImageController extends Controller |
|
248
|
}
|
249
|
}
|
|
249
|
|
250
|
|
|
250
|
/**
|
251
|
/**
|
|
251
|
- * @param $files
|
|
|
|
252
|
* @remark :多图片上传
|
252
|
* @remark :多图片上传
|
|
253
|
* @name :multi
|
253
|
* @name :multi
|
|
254
|
* @author :lyh
|
254
|
* @author :lyh
|
|
@@ -263,7 +263,12 @@ class ImageController extends Controller |
|
@@ -263,7 +263,12 @@ class ImageController extends Controller |
|
263
|
$mime = $file->getMimeType();
|
263
|
$mime = $file->getMimeType();
|
|
264
|
$imageModel = new ImageModel();
|
264
|
$imageModel = new ImageModel();
|
|
265
|
$hash = hash_file('md5', $file->getPathname());
|
265
|
$hash = hash_file('md5', $file->getPathname());
|
|
266
|
- $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
|
266
|
+ //查看图片是否已上传
|
|
|
|
267
|
+ $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0];
|
|
|
|
268
|
+ if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
|
|
|
|
269
|
+ $param['project_id'] = $this->cache['project_id'];
|
|
|
|
270
|
+ }
|
|
|
|
271
|
+ $image_hash = $imageModel->read($param);
|
|
267
|
if($image_hash !== false){
|
272
|
if($image_hash !== false){
|
|
268
|
$data[] = $this->responseData($image_hash['path']);
|
273
|
$data[] = $this->responseData($image_hash['path']);
|
|
269
|
continue;
|
274
|
continue;
|
|
@@ -275,10 +280,7 @@ class ImageController extends Controller |
|
@@ -275,10 +280,7 @@ class ImageController extends Controller |
|
275
|
$cosService = new CosService();
|
280
|
$cosService = new CosService();
|
|
276
|
$cosService->uploadFile($file,$this->path,$fileName);
|
281
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
277
|
}else{
|
282
|
}else{
|
|
278
|
- $res = $file->move($url,$fileName);
|
|
|
|
279
|
- if ($res === false) {
|
|
|
|
280
|
- $this->response($file->getError(), Code::USER_ERROR);
|
|
|
|
281
|
- }
|
283
|
+ $file->move($url,$fileName);
|
|
282
|
}
|
284
|
}
|
|
283
|
//批量存储
|
285
|
//批量存储
|
|
284
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|
286
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
|