正在显示
1 个修改的文件
包含
20 行增加
和
13 行删除
| @@ -55,16 +55,8 @@ class ImageController extends Controller | @@ -55,16 +55,8 @@ class ImageController extends Controller | ||
| 55 | return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']); | 55 | return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'当前用户未登录']); |
| 56 | } | 56 | } |
| 57 | $this->param = $this->request->all(); | 57 | $this->param = $this->request->all(); |
| 58 | - if(!isset($this->param['image_type'])){ | ||
| 59 | - return response(['code'=>Code::USER_LOGIN_ERROE,'msg'=>'参数错误']); | ||
| 60 | - } | ||
| 61 | $this->config = config('filesystems.disks.upload'); | 58 | $this->config = config('filesystems.disks.upload'); |
| 62 | $this->uploads = config('upload.default_image'); | 59 | $this->uploads = config('upload.default_image'); |
| 63 | - if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ | ||
| 64 | - $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m'); | ||
| 65 | - }else{ | ||
| 66 | - $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m'); | ||
| 67 | - } | ||
| 68 | } | 60 | } |
| 69 | 61 | ||
| 70 | /** | 62 | /** |
| @@ -87,7 +79,7 @@ class ImageController extends Controller | @@ -87,7 +79,7 @@ class ImageController extends Controller | ||
| 87 | $this->response('指定图片不存在!', Code::USER_ERROR); | 79 | $this->response('指定图片不存在!', Code::USER_ERROR); |
| 88 | } | 80 | } |
| 89 | //查看缩略图是否存在 | 81 | //查看缩略图是否存在 |
| 90 | - $filename = $this->config['root'].'/'.$this->path . '/' . $info['hash'] . $w . '_' . $h; | 82 | + $filename = $this->config['root'] . '/' .$info['path'] . '_' . $w . '_' . $h; |
| 91 | if(is_file($filename)){ | 83 | if(is_file($filename)){ |
| 92 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; | 84 | $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; |
| 93 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], | 85 | $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], |
| @@ -133,6 +125,7 @@ class ImageController extends Controller | @@ -133,6 +125,7 @@ class ImageController extends Controller | ||
| 133 | $this->response('没有上传的文件!', 400); | 125 | $this->response('没有上传的文件!', 400); |
| 134 | } | 126 | } |
| 135 | $type = $this->request->post('type','single'); | 127 | $type = $this->request->post('type','single'); |
| 128 | + $this->setUrl(); | ||
| 136 | if ($type == 'multi') { | 129 | if ($type == 'multi') { |
| 137 | return $this->multi($files); | 130 | return $this->multi($files); |
| 138 | } else { | 131 | } else { |
| @@ -150,7 +143,6 @@ class ImageController extends Controller | @@ -150,7 +143,6 @@ class ImageController extends Controller | ||
| 150 | */ | 143 | */ |
| 151 | public function single($files){ | 144 | public function single($files){ |
| 152 | $hash = hash_file('md5', $files->getPathname()); | 145 | $hash = hash_file('md5', $files->getPathname()); |
| 153 | - | ||
| 154 | //查看文件是否存在 | 146 | //查看文件是否存在 |
| 155 | $imageModel = new ImageModel(); | 147 | $imageModel = new ImageModel(); |
| 156 | $image_hash = $imageModel->read(['hash'=>$hash]); | 148 | $image_hash = $imageModel->read(['hash'=>$hash]); |
| @@ -158,8 +150,6 @@ class ImageController extends Controller | @@ -158,8 +150,6 @@ class ImageController extends Controller | ||
| 158 | return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); | 150 | return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); |
| 159 | } | 151 | } |
| 160 | $url = $this->config['root'].'/'.$this->path; | 152 | $url = $this->config['root'].'/'.$this->path; |
| 161 | - var_dump($this->path); | ||
| 162 | - die(); | ||
| 163 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 153 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); |
| 164 | $res = $files->move($url,$fileName); | 154 | $res = $files->move($url,$fileName); |
| 165 | if ($res === false) { | 155 | if ($res === false) { |
| @@ -192,7 +182,7 @@ class ImageController extends Controller | @@ -192,7 +182,7 @@ class ImageController extends Controller | ||
| 192 | */ | 182 | */ |
| 193 | private function cacheImage($info, $w, $h) { | 183 | private function cacheImage($info, $w, $h) { |
| 194 | $path = $info['path']; | 184 | $path = $info['path']; |
| 195 | - $filename = $this->config['url'] . $this->path . $info['hash'] . $w . '_' . $h; | 185 | + $filename = $this->config['url'] . '/' . $info['path'] . '_' . $w . '_' . $h; |
| 196 | Image::make($path)->resize($w, $h)->save($filename); | 186 | Image::make($path)->resize($w, $h)->save($filename); |
| 197 | return $filename; | 187 | return $filename; |
| 198 | } | 188 | } |
| @@ -314,4 +304,21 @@ class ImageController extends Controller | @@ -314,4 +304,21 @@ class ImageController extends Controller | ||
| 314 | $this->response('success',Code::SUCCESS,$lists); | 304 | $this->response('success',Code::SUCCESS,$lists); |
| 315 | } | 305 | } |
| 316 | 306 | ||
| 307 | + /** | ||
| 308 | + * @remark :保存路径 | ||
| 309 | + * @name :setUrl | ||
| 310 | + * @author :lyh | ||
| 311 | + * @method :post | ||
| 312 | + * @time :2023/7/18 15:36 | ||
| 313 | + */ | ||
| 314 | + public function setUrl(){ | ||
| 315 | + if(!isset($this->param['image_type'])){ | ||
| 316 | + $this->response('参数错误',Code::USER_ERROR); | ||
| 317 | + } | ||
| 318 | + if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ | ||
| 319 | + $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m'); | ||
| 320 | + }else{ | ||
| 321 | + $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['image_type']].'/'.date('Y-m'); | ||
| 322 | + } | ||
| 323 | + } | ||
| 317 | } | 324 | } |
-
请 注册 或 登录 后发表评论