|
...
|
...
|
@@ -12,7 +12,6 @@ use App\Services\TencentCosService; |
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Intervention\Image\Facades\Image;
|
|
|
|
|
|
|
|
class ImageController extends Controller
|
|
...
|
...
|
@@ -62,9 +61,6 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $hash
|
|
|
|
* @param $w
|
|
|
|
* @param $h
|
|
|
|
* @name :index
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
...
|
...
|
@@ -152,7 +148,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;
|
|
...
|
...
|
@@ -167,7 +163,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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -227,7 +223,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;
|
|
...
|
...
|
@@ -239,14 +235,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,17 +253,31 @@ class ImageController extends Controller |
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/19 17:59
|
|
|
|
*/
|
|
|
|
public function download($filename){
|
|
|
|
$path = Storage::path($filename);
|
|
|
|
return response()->download($path,time().rand(1,100000));
|
|
|
|
public function download(){
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$info = $imageModel->read(['hash' => $this->param['hash']]);
|
|
|
|
if ($info === false) {
|
|
|
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
if($info['is_cos'] == 1){
|
|
|
|
$cos = new CosService();
|
|
|
|
$fileUrl = $cos->getImageUrl($info['path']);
|
|
|
|
}else{
|
|
|
|
$fileUrl = $this->config['root'].$info['path'];
|
|
|
|
if (!is_file($fileUrl)) {
|
|
|
|
$this->response('指定图片已被系统删除!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$fileName = basename($info['path']); // 要保存的文件名
|
|
|
|
// 设置响应头
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
|
|
// 下载文件
|
|
|
|
readfile($fileUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $msg
|
|
|
|
* @param string $code
|
|
|
|
* @param $data
|
|
|
|
* @param $result_code
|
|
|
|
* @param $type
|
|
|
|
* @remark :统一返回
|
|
|
|
* @name :response
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -349,4 +359,37 @@ 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取下载链接
|
|
|
|
* @name :getDownloadUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/26 14:00
|
|
|
|
*/
|
|
|
|
public function getDownloadUrl(){
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$info = $imageModel->read(['hash' => $this->param['hash']]);
|
|
|
|
if ($info === false) {
|
|
|
|
$this->response('指定文件不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$data = ['image_download'=>url('a/downLoad/images?hash='.$this->param['hash'])];
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|