正在显示
1 个修改的文件
包含
9 行增加
和
6 行删除
| @@ -120,6 +120,9 @@ class ImageController extends Controller | @@ -120,6 +120,9 @@ class ImageController extends Controller | ||
| 120 | 'image.required'=>'图片必须填写', | 120 | 'image.required'=>'图片必须填写', |
| 121 | ]); | 121 | ]); |
| 122 | $files = $this->request->file('image'); | 122 | $files = $this->request->file('image'); |
| 123 | + $size = $files->getSize(); | ||
| 124 | + var_dump($size); | ||
| 125 | + die(); | ||
| 123 | if (empty($files)) { | 126 | if (empty($files)) { |
| 124 | $this->response('没有上传的文件!', 400); | 127 | $this->response('没有上传的文件!', 400); |
| 125 | } | 128 | } |
| @@ -155,14 +158,14 @@ class ImageController extends Controller | @@ -155,14 +158,14 @@ class ImageController extends Controller | ||
| 155 | $cosService = new CosService(); | 158 | $cosService = new CosService(); |
| 156 | $cosService->uploadFile($files,$this->path,$fileName); | 159 | $cosService->uploadFile($files,$this->path,$fileName); |
| 157 | }else{ | 160 | }else{ |
| 158 | - var_dump(11111); | ||
| 159 | - die(); | ||
| 160 | $res = $files->move($url,$fileName); | 161 | $res = $files->move($url,$fileName); |
| 162 | + $size = $res->getSize(); | ||
| 163 | + $image_type = $files->getClientOriginalExtension(); | ||
| 161 | if ($res === false) { | 164 | if ($res === false) { |
| 162 | return $this->response($files->getError(), Code::USER_ERROR); | 165 | return $this->response($files->getError(), Code::USER_ERROR); |
| 163 | } | 166 | } |
| 164 | } | 167 | } |
| 165 | - $this->saveMysql($imageModel,$files,$fileName,$hash); | 168 | + $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash); |
| 166 | return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); | 169 | return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); |
| 167 | } | 170 | } |
| 168 | 171 | ||
| @@ -173,13 +176,13 @@ class ImageController extends Controller | @@ -173,13 +176,13 @@ class ImageController extends Controller | ||
| 173 | * @method :post | 176 | * @method :post |
| 174 | * @time :2023/7/19 16:38 | 177 | * @time :2023/7/19 16:38 |
| 175 | */ | 178 | */ |
| 176 | - public function saveMysql(&$imageModel,&$files,$fileName,$hash){ | 179 | + public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash){ |
| 177 | $data = [ | 180 | $data = [ |
| 178 | 'path' => $this->path.'/'.$fileName, | 181 | 'path' => $this->path.'/'.$fileName, |
| 179 | 'created_at' => date('Y-m-d H:i:s',time()), | 182 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 180 | - 'size' => $files->getSize(), | 183 | + 'size' => $size, |
| 181 | 'hash' => $hash, | 184 | 'hash' => $hash, |
| 182 | - 'type'=>$files->getClientOriginalExtension(), | 185 | + 'type'=>$image_type, |
| 183 | 'refer'=>$this->param['refer'] ?? 1, | 186 | 'refer'=>$this->param['refer'] ?? 1, |
| 184 | ]; | 187 | ]; |
| 185 | $rs = $imageModel->add($data); | 188 | $rs = $imageModel->add($data); |
-
请 注册 或 登录 后发表评论