Browse Source

上传多图片文件夹

wzq 5 years ago
parent
commit
262433efbb
1 changed files with 3 additions and 2 deletions
  1. 3 2
      app/Http/Controllers/UploadController.php

+ 3 - 2
app/Http/Controllers/UploadController.php

@@ -47,6 +47,7 @@ class UploadController extends Controller
         $files = $request->file('image');
         $fileCount = count($files);
         $urls = [];
+        $path = $request->get('path') ? $request->get('path') . '/' : date('Ym') . '/';
         for ($i = 0; $i < $fileCount; $i++) {
             $kuoname = $files[$i]->getClientOriginalExtension();
             $filePath = $files[$i]->getRealPath();
@@ -61,9 +62,9 @@ class UploadController extends Controller
                 //要保存的文件名 时间+扩展名
                 $filename = time() . '_' . uniqid() . '.' . $kuoname;
             }
-            $imageUrl = Storage::put($filename, file_get_contents($filePath));
+            $imageUrl = Storage::put($path . $filename, file_get_contents($filePath));
             if ($imageUrl) {
-                array_push($urls, config('customer.chxq_oss_url') . $filename);
+                array_push($urls, config('customer.chxq_oss_url') . $path . $filename);
             } else {
                 Log::debug('文件上传失败。' . $filename);
             }