|
@@ -151,7 +151,7 @@ class ImageController extends Controller |
|
@@ -151,7 +151,7 @@ class ImageController extends Controller |
|
151
|
$imageModel = new ImageModel();
|
151
|
$imageModel = new ImageModel();
|
|
152
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
152
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
153
|
if($image_hash !== false){
|
153
|
if($image_hash !== false){
|
|
154
|
- return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
|
154
|
+ return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
|
|
155
|
}
|
155
|
}
|
|
156
|
$url = $this->config['root'].$this->path;
|
156
|
$url = $this->config['root'].$this->path;
|
|
157
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
157
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
@@ -166,7 +166,7 @@ class ImageController extends Controller |
|
@@ -166,7 +166,7 @@ class ImageController extends Controller |
|
166
|
}
|
166
|
}
|
|
167
|
}
|
167
|
}
|
|
168
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
168
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
169
|
- return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
|
169
|
+ return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
|
|
170
|
}
|
170
|
}
|
|
171
|
|
171
|
|
|
172
|
/**
|
172
|
/**
|
|
@@ -226,7 +226,7 @@ class ImageController extends Controller |
|
@@ -226,7 +226,7 @@ class ImageController extends Controller |
|
226
|
$hash = hash_file('md5', $file->getPathname());
|
226
|
$hash = hash_file('md5', $file->getPathname());
|
|
227
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
227
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
228
|
if($image_hash !== false){
|
228
|
if($image_hash !== false){
|
|
229
|
- $data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
229
|
+ $data[] = $this->responseData($hash);
|
|
230
|
continue;
|
230
|
continue;
|
|
231
|
}
|
231
|
}
|
|
232
|
$url = $this->config['root'].$this->path;
|
232
|
$url = $this->config['root'].$this->path;
|
|
@@ -238,14 +238,14 @@ class ImageController extends Controller |
|
@@ -238,14 +238,14 @@ class ImageController extends Controller |
|
238
|
}else{
|
238
|
}else{
|
|
239
|
$res = $file->move($url,$fileName);
|
239
|
$res = $file->move($url,$fileName);
|
|
240
|
if ($res === false) {
|
240
|
if ($res === false) {
|
|
241
|
- return $this->response($file->getError(), Code::USER_ERROR);
|
241
|
+ $this->response($file->getError(), Code::USER_ERROR);
|
|
242
|
}
|
242
|
}
|
|
243
|
}
|
243
|
}
|
|
244
|
//批量存储
|
244
|
//批量存储
|
|
245
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
245
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
246
|
- $data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
246
|
+ $data[] = $this->responseData($hash);
|
|
247
|
}
|
247
|
}
|
|
248
|
- return $this->response('图片资源',Code::SUCCESS,$data);
|
248
|
+ $this->response('图片资源',Code::SUCCESS,$data);
|
|
249
|
}
|
249
|
}
|
|
250
|
|
250
|
|
|
251
|
/**
|
251
|
/**
|
|
@@ -257,7 +257,6 @@ class ImageController extends Controller |
|
@@ -257,7 +257,6 @@ class ImageController extends Controller |
|
257
|
* @time :2023/7/19 17:59
|
257
|
* @time :2023/7/19 17:59
|
|
258
|
*/
|
258
|
*/
|
|
259
|
public function download(){
|
259
|
public function download(){
|
|
260
|
- $this->setHeader();
|
|
|
|
261
|
$imageModel = new ImageModel();
|
260
|
$imageModel = new ImageModel();
|
|
262
|
$info = $imageModel->read(['hash' => $this->param['hash']]);
|
261
|
$info = $imageModel->read(['hash' => $this->param['hash']]);
|
|
263
|
if ($info === false) {
|
262
|
if ($info === false) {
|
|
@@ -281,25 +280,7 @@ class ImageController extends Controller |
|
@@ -281,25 +280,7 @@ class ImageController extends Controller |
|
281
|
readfile($fileUrl);
|
280
|
readfile($fileUrl);
|
|
282
|
}
|
281
|
}
|
|
283
|
|
282
|
|
|
284
|
- public function setHeader(){
|
|
|
|
285
|
- // 设置跨域请求头部
|
|
|
|
286
|
- header('Access-Control-Allow-Origin: *');
|
|
|
|
287
|
- header('Access-Control-Allow-Methods: GET');
|
|
|
|
288
|
- header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
289
|
- // 处理预检请求
|
|
|
|
290
|
- if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
291
|
- header('Access-Control-Allow-Origin: *');
|
|
|
|
292
|
- header('Access-Control-Allow-Methods: GET');
|
|
|
|
293
|
- header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
294
|
- exit;
|
|
|
|
295
|
- }
|
|
|
|
296
|
- }
|
|
|
|
297
|
/**
|
283
|
/**
|
|
298
|
- * @param $msg
|
|
|
|
299
|
- * @param string $code
|
|
|
|
300
|
- * @param $data
|
|
|
|
301
|
- * @param $result_code
|
|
|
|
302
|
- * @param $type
|
|
|
|
303
|
* @remark :统一返回
|
284
|
* @remark :统一返回
|
|
304
|
* @name :response
|
285
|
* @name :response
|
|
305
|
* @author :lyh
|
286
|
* @author :lyh
|
|
@@ -381,4 +362,20 @@ class ImageController extends Controller |
|
@@ -381,4 +362,20 @@ class ImageController extends Controller |
|
381
|
}
|
362
|
}
|
|
382
|
return $url;
|
363
|
return $url;
|
|
383
|
}
|
364
|
}
|
|
|
|
365
|
+
|
|
|
|
366
|
+ /**
|
|
|
|
367
|
+ * @remark :统一返回参数处理
|
|
|
|
368
|
+ * @name :responseData
|
|
|
|
369
|
+ * @author :lyh
|
|
|
|
370
|
+ * @method :post
|
|
|
|
371
|
+ * @time :2023/7/26 13:41
|
|
|
|
372
|
+ */
|
|
|
|
373
|
+ public function responseData($hash){
|
|
|
|
374
|
+ $data = [
|
|
|
|
375
|
+ 'image'=>$hash,
|
|
|
|
376
|
+ 'image_link'=>$this->getImageUrl($hash),
|
|
|
|
377
|
+ 'image_download'=>url('a/download/images?hash='.$hash),
|
|
|
|
378
|
+ ];
|
|
|
|
379
|
+ return $data;
|
|
|
|
380
|
+ }
|
|
384
|
} |
381
|
} |