正在显示
1 个修改的文件
包含
9 行增加
和
7 行删除
| @@ -128,7 +128,7 @@ class ImageController extends Controller | @@ -128,7 +128,7 @@ class ImageController extends Controller | ||
| 128 | $type = $this->request->post('type','single'); | 128 | $type = $this->request->post('type','single'); |
| 129 | $this->setUrl(); | 129 | $this->setUrl(); |
| 130 | if ($type == 'multi') { | 130 | if ($type == 'multi') { |
| 131 | - return $this->multi($files,$size,$image_type); | 131 | + return $this->multi($files); |
| 132 | }else{ | 132 | }else{ |
| 133 | return $this->single($files,$size,$image_type); | 133 | return $this->single($files,$size,$image_type); |
| 134 | } | 134 | } |
| @@ -142,7 +142,7 @@ class ImageController extends Controller | @@ -142,7 +142,7 @@ class ImageController extends Controller | ||
| 142 | * @method :post | 142 | * @method :post |
| 143 | * @time :2023/6/17 16:30 | 143 | * @time :2023/6/17 16:30 |
| 144 | */ | 144 | */ |
| 145 | - public function single($files,$size,$image_type){ | 145 | + public function single(&$files,$size,$image_type){ |
| 146 | $hash = hash_file('md5', $files->getPathname()); | 146 | $hash = hash_file('md5', $files->getPathname()); |
| 147 | //查看文件是否存在 | 147 | //查看文件是否存在 |
| 148 | $imageModel = new ImageModel(); | 148 | $imageModel = new ImageModel(); |
| @@ -213,13 +213,15 @@ class ImageController extends Controller | @@ -213,13 +213,15 @@ class ImageController extends Controller | ||
| 213 | * @method :post | 213 | * @method :post |
| 214 | * @time :2023/6/17 16:31 | 214 | * @time :2023/6/17 16:31 |
| 215 | */ | 215 | */ |
| 216 | - private function multi($files) { | 216 | + private function multi(&$files) { |
| 217 | if (!is_array($files)) { | 217 | if (!is_array($files)) { |
| 218 | $files = [$files]; | 218 | $files = [$files]; |
| 219 | } | 219 | } |
| 220 | $save_data = []; | 220 | $save_data = []; |
| 221 | $data = []; | 221 | $data = []; |
| 222 | foreach ($files as $file) { | 222 | foreach ($files as $file) { |
| 223 | + $size = $file->getSize(); | ||
| 224 | + $image_type = $file->getClientOriginalExtension(); | ||
| 223 | $imageModel = new ImageModel(); | 225 | $imageModel = new ImageModel(); |
| 224 | $hash = hash_file('md5', $file->getPathname()); | 226 | $hash = hash_file('md5', $file->getPathname()); |
| 225 | $image_hash = $imageModel->read(['hash'=>$hash]); | 227 | $image_hash = $imageModel->read(['hash'=>$hash]); |
| @@ -237,16 +239,16 @@ class ImageController extends Controller | @@ -237,16 +239,16 @@ class ImageController extends Controller | ||
| 237 | 'path' => $this->path.'/'.$fileName, | 239 | 'path' => $this->path.'/'.$fileName, |
| 238 | 'created_at' => date('Y-m-d H:i:s',time()), | 240 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 239 | 'updated_at'=>date('Y-m-d H:i:s',time()), | 241 | 'updated_at'=>date('Y-m-d H:i:s',time()), |
| 240 | - 'size' => $res->getSize(), | 242 | + 'size' => $size, |
| 241 | 'hash' => $hash, | 243 | 'hash' => $hash, |
| 242 | - 'type'=>$file->getClientOriginalExtension(), | ||
| 243 | - 'refer'=>$this->param['refer'] ?? '', | 244 | + 'type'=>$image_type, |
| 245 | + 'refer'=>$this->param['refer'] ?? 0, | ||
| 244 | ]; | 246 | ]; |
| 245 | $data[] = ['image'=>$hash]; | 247 | $data[] = ['image'=>$hash]; |
| 246 | //同步数据到cos | 248 | //同步数据到cos |
| 247 | if($this->upload_location == 1){ | 249 | if($this->upload_location == 1){ |
| 248 | $cosService = new CosService(); | 250 | $cosService = new CosService(); |
| 249 | - $cosService->uploadFile($this->path,$fileName); | 251 | + $cosService->uploadFile($file,$this->path,$fileName); |
| 250 | } | 252 | } |
| 251 | } | 253 | } |
| 252 | $imageModel->insert($save_data); | 254 | $imageModel->insert($save_data); |
-
请 注册 或 登录 后发表评论