|
...
|
...
|
@@ -151,7 +151,7 @@ class ImageController extends Controller |
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($image_hash !== false){
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
|
|
...
|
...
|
@@ -166,7 +166,7 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -226,7 +226,7 @@ class ImageController extends Controller |
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($image_hash !== false){
|
|
|
|
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
|
|
|
$data[] = $this->responseData($hash);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].$this->path;
|
|
...
|
...
|
@@ -238,14 +238,14 @@ class ImageController extends Controller |
|
|
|
}else{
|
|
|
|
$res = $file->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($file->getError(), Code::USER_ERROR);
|
|
|
|
$this->response($file->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//批量存储
|
|
|
|
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
|
|
|
|
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
|
|
|
|
$data[] = $this->responseData($hash);
|
|
|
|
}
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
$this->response('图片资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -257,7 +257,6 @@ class ImageController extends Controller |
|
|
|
* @time :2023/7/19 17:59
|
|
|
|
*/
|
|
|
|
public function download(){
|
|
|
|
$this->setHeader();
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$info = $imageModel->read(['hash' => $this->param['hash']]);
|
|
|
|
if ($info === false) {
|
|
...
|
...
|
@@ -281,25 +280,7 @@ class ImageController extends Controller |
|
|
|
readfile($fileUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHeader(){
|
|
|
|
// 设置跨域请求头部
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
header('Access-Control-Allow-Methods: GET');
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
// 处理预检请求
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
header('Access-Control-Allow-Methods: GET');
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param $msg
|
|
|
|
* @param string $code
|
|
|
|
* @param $data
|
|
|
|
* @param $result_code
|
|
|
|
* @param $type
|
|
|
|
* @remark :统一返回
|
|
|
|
* @name :response
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -381,4 +362,20 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :统一返回参数处理
|
|
|
|
* @name :responseData
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/26 13:41
|
|
|
|
*/
|
|
|
|
public function responseData($hash){
|
|
|
|
$data = [
|
|
|
|
'image'=>$hash,
|
|
|
|
'image_link'=>$this->getImageUrl($hash),
|
|
|
|
'image_download'=>url('a/download/images?hash='.$hash),
|
|
|
|
];
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|