xielin 5 anni fa
parent
commit
9b20005a0c
1 ha cambiato i file con 8 aggiunte e 6 eliminazioni
  1. 8 6
      app/Http/Controllers/UploadController.php

+ 8 - 6
app/Http/Controllers/UploadController.php

@@ -27,15 +27,16 @@ class UploadController extends Controller
                 $width = Image::make($filePath)->width();
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
+                $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                $fileurl = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
             } else {
                 //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                $fileurl = $filename = time() . '_' . uniqid() . '.' . $kuoname;
             }
             $imageUrl = Storage::put($path . $filename, file_get_contents($filePath));
             if ($imageUrl) {
                 return [
-                    'data' => ['url' => $path . $filename]
+                    'data' => ['url' => $path . $fileurl]
                 ];
             } else {
                 return $this->response->error('图片上传失败,请重试', 500);
@@ -59,14 +60,15 @@ class UploadController extends Controller
                 $height = Image::make($filePath)->height();
                 //要保存的文件名 时间+扩展名
                 //$filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
-                $filename = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
+                $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                $fileurl = time() . '_' . uniqid() . '.' . $kuoname . '?' . $width . '_' . $height;
             } else {
                 //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                $fileurl = $filename = time() . '_' . uniqid() . '.' . $kuoname;
             }
             $imageUrl = Storage::put($filename, file_get_contents($filePath));
             if ($imageUrl) {
-                array_push($urls, $filename);
+                array_push($urls, $fileurl);
             } else {
                 Log::debug('文件上传失败。' . $filename);
             }