作者 lyh

gx

@@ -179,9 +179,6 @@ class ImageController extends Controller @@ -179,9 +179,6 @@ class ImageController extends Controller
179 * @time :2023/6/17 16:30 179 * @time :2023/6/17 16:30
180 */ 180 */
181 public function single(&$files){ 181 public function single(&$files){
182 - $size = $files->getSize();  
183 - $image_type = $files->getClientOriginalExtension();  
184 - $mime = $files->getMimeType();  
185 $hash = hash_file('md5', $files->getPathname()); 182 $hash = hash_file('md5', $files->getPathname());
186 //查看文件是否存在 183 //查看文件是否存在
187 $imageModel = new ImageModel(); 184 $imageModel = new ImageModel();
@@ -196,6 +193,7 @@ class ImageController extends Controller @@ -196,6 +193,7 @@ class ImageController extends Controller
196 } 193 }
197 //保存路径 194 //保存路径
198 $url = $this->config['root'].$this->path; 195 $url = $this->config['root'].$this->path;
  196 + $image_type = $files->getClientOriginalExtension();
199 $fileName = uniqid().rand(10000,99999).'.'.$image_type; 197 $fileName = uniqid().rand(10000,99999).'.'.$image_type;
200 //上传到cos 198 //上传到cos
201 if($this->upload_location == 1){ 199 if($this->upload_location == 1){
@@ -204,7 +202,7 @@ class ImageController extends Controller @@ -204,7 +202,7 @@ class ImageController extends Controller
204 }else{ 202 }else{
205 $files->move($url,$fileName); 203 $files->move($url,$fileName);
206 } 204 }
207 - $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime); 205 + $this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType());
208 return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName)); 206 return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
209 } 207 }
210 208
@@ -258,9 +256,6 @@ class ImageController extends Controller @@ -258,9 +256,6 @@ class ImageController extends Controller
258 private function multi(&$files) { 256 private function multi(&$files) {
259 $data = []; 257 $data = [];
260 foreach ($files as $file) { 258 foreach ($files as $file) {
261 - $size = $file->getSize();  
262 - $image_type = $file->getClientOriginalExtension();  
263 - $mime = $file->getMimeType();  
264 $imageModel = new ImageModel(); 259 $imageModel = new ImageModel();
265 $hash = hash_file('md5', $file->getPathname()); 260 $hash = hash_file('md5', $file->getPathname());
266 //查看图片是否已上传 261 //查看图片是否已上传
@@ -274,7 +269,8 @@ class ImageController extends Controller @@ -274,7 +269,8 @@ class ImageController extends Controller
274 continue; 269 continue;
275 } 270 }
276 $url = $this->config['root'].$this->path; 271 $url = $this->config['root'].$this->path;
277 - $fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension(); 272 + $image_type = $file->getClientOriginalExtension();
  273 + $fileName = uniqid().rand(10000,99999).'.'.$image_type;
278 //同步数据到cos 274 //同步数据到cos
279 if($this->upload_location == 1){ 275 if($this->upload_location == 1){
280 $cosService = new CosService(); 276 $cosService = new CosService();
@@ -283,7 +279,7 @@ class ImageController extends Controller @@ -283,7 +279,7 @@ class ImageController extends Controller
283 $file->move($url,$fileName); 279 $file->move($url,$fileName);
284 } 280 }
285 //批量存储 281 //批量存储
286 - $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime); 282 + $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType());
287 $data[] = $this->responseData($this->path.'/'.$fileName); 283 $data[] = $this->responseData($this->path.'/'.$fileName);
288 } 284 }
289 $this->response('图片资源',Code::SUCCESS,$data); 285 $this->response('图片资源',Code::SUCCESS,$data);