Bläddra i källkod

Merge branch 'develop'

xielin 5 år sedan
förälder
incheckning
cf6cf5cbd0
1 ändrade filer med 20 tillägg och 19 borttagningar
  1. 20 19
      app/Http/Controllers/UploadController.php

+ 20 - 19
app/Http/Controllers/UploadController.php

@@ -13,29 +13,30 @@ class UploadController extends Controller
     {
         if ($request->hasFile('image') && $request->file('image')->isValid()) {
             $path = $request->get('path') ? $request->get('path') . '/' : date('Ym') . '/';
-//            //获取文件的扩展名
             $kuoname = $request->file('image')->getClientOriginalExtension();
 
-//            //获取文件的类型
-//            $type=$request->file('image')->getClientMimeType();
-//            //获取文件的绝对路径,但是获取到的在本地不能打开
             $filePath = $request->file('image')->getRealPath();
             Log::debug('文件类型'.$kuoname);
-            if (in_array($kuoname, ['jpg', 'jpeg', 'gif', 'png'])) {
-                $width = Image::make($filePath)->width();
-                $height = Image::make($filePath)->height();
-                //要保存的文件名 时间+扩展名
-                $filename = time() . '_' . uniqid() . '.' . $kuoname;
-                $fileurl = $filename . '?' . $width . '_' . $height;
-            } else {
-                //要保存的文件名 时间+扩展名
-                $fileurl = $filename = time() . '_' . uniqid() . '.' . $kuoname;
-            }
-            $imageUrl = Storage::put($path . $filename, file_get_contents($filePath));
-            Log::debug('upload_url:' . $imageUrl);
-            if ($imageUrl) {
-                return $this->jsonSuccess(['url' => config('customer.chxq_oss_url') . $path . $fileurl]);
-            } else {
+            try{
+                if (in_array($kuoname, ['jpg', 'jpeg', 'gif', 'png'])) {
+                    $width = Image::make($filePath)->width();
+                    $height = Image::make($filePath)->height();
+                    //要保存的文件名 时间+扩展名
+                    $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                    $fileurl = $filename . '?' . $width . '_' . $height;
+                } else {
+                    //要保存的文件名 时间+扩展名
+                    $fileurl = $filename = time() . '_' . uniqid() . '.' . $kuoname;
+                }
+                $imageUrl = Storage::put($path . $filename, file_get_contents($filePath));
+                Log::debug('upload_url:' . $imageUrl);
+                if ($imageUrl) {
+                    return $this->jsonSuccess(['url' => config('customer.chxq_oss_url') . $path . $fileurl]);
+                } else {
+                    return $this->jsonError('图片上传失败,请重试');
+                }
+            }catch (\Exception $exception){
+                Log::error('upload-exception:'.$exception->getMessage());
                 return $this->jsonError('图片上传失败,请重试');
             }
         } else {