yingzi 2 years ago
parent
commit
73247bd49d
1 changed files with 35 additions and 0 deletions
  1. 35 0
      app/system/controller/Upload.php

+ 35 - 0
app/system/controller/Upload.php

@@ -20,7 +20,42 @@ use think\Image;
 class Upload extends AuthController{
 
 
+    /**
+     * 七牛上传
+     * @param Request $request
+     */
     public function index(Request $request){
+        $file = $request->file('file');
+        if (empty($file)) {
+            return app('json')->fail("未上传文件");
+        }
+        $rootTmp    = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
+        $image_size = @getimagesize($rootTmp);
+        if ($image_size[0] > 1000) {
+            $imgS = Image::open($rootTmp);
+            $imgS->thumb(1000, $image_size[1]);
+            $imgS->save($rootTmp);
+        } else {
+            if ($image_size[1] > 1000) {
+                $imgS = Image::open($rootTmp);
+                $imgS->thumb($image_size[0], 1000);
+                $imgS->save($rootTmp);
+            }
+        }
+        $qiniu   = new  Qiniu;
+        $img_url = $qiniu->updateFile('sysimg', $rootTmp, $rootTmp);
+        if (empty($img_url['url'])) {
+            return app('json')->fail($qiniu->getError());
+        }
+        @unlink($rootTmp);
+        return app('json')->success(['img' => $img_url['url']]);
+    }
+    /**
+     * 本地上传
+     * @param Request $request
+     * @return type
+     */
+    public function index2(Request $request){
         $uploadConfig = config('filesystem');
         $sysData = (new SysModel())->where("id",1)->find();
         $file = $request->file('file');