|
...
|
...
|
@@ -55,16 +55,8 @@ class ImageController extends Controller |
|
|
|
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']);
|
|
|
|
}
|
|
|
|
$this->param = $this->request->all();
|
|
|
|
if(!isset($this->param['image_type'])){
|
|
|
|
return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'参数错误']);
|
|
|
|
}
|
|
|
|
$this->config = config('filesystems.disks.upload');
|
|
|
|
$this->uploads = config('upload.default_image');
|
|
|
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m');
|
|
|
|
}else{
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -87,7 +79,7 @@ class ImageController extends Controller |
|
|
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//查看缩略图是否存在
|
|
|
|
$filename = $this->config['root'].'/'.$this->path . '/' . $info['hash'] . $w . '_' . $h;
|
|
|
|
$filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h;
|
|
|
|
if(is_file($filename)){
|
|
|
|
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
|
|
|
|
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
|
|
...
|
...
|
@@ -133,6 +125,7 @@ class ImageController extends Controller |
|
|
|
$this->response('没有上传的文件!', 400);
|
|
|
|
}
|
|
|
|
$type = $this->request->post('type','single');
|
|
|
|
$this->setUrl();
|
|
|
|
if ($type == 'multi') {
|
|
|
|
return $this->multi($files);
|
|
|
|
} else {
|
|
...
|
...
|
@@ -150,7 +143,6 @@ class ImageController extends Controller |
|
|
|
*/
|
|
|
|
public function single($files){
|
|
|
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
|
|
|
|
//查看文件是否存在
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
...
|
...
|
@@ -158,8 +150,6 @@ class ImageController extends Controller |
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].'/'.$this->path;
|
|
|
|
var_dump($this->path);
|
|
|
|
die();
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
...
|
...
|
@@ -192,7 +182,7 @@ class ImageController extends Controller |
|
|
|
*/
|
|
|
|
private function cacheImage($info, $w, $h) {
|
|
|
|
$path = $info['path'];
|
|
|
|
$filename = $this->config['url'] . $this->path . $info['hash'] . $w . '_' . $h;
|
|
|
|
$filename = $this->config['url'] . '/' . $info['path'] . '_' . $w . '_' . $h;
|
|
|
|
Image::make($path)->resize($w, $h)->save($filename);
|
|
|
|
return $filename;
|
|
|
|
}
|
|
...
|
...
|
@@ -314,4 +304,21 @@ class ImageController extends Controller |
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存路径
|
|
|
|
* @name :setUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/18 15:36
|
|
|
|
*/
|
|
|
|
public function setUrl(){
|
|
|
|
if(!isset($this->param['image_type'])){
|
|
|
|
$this->response('参数错误',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m');
|
|
|
|
}else{
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|