laravel调用webuploader插件

简要描述:

  • laravel结合webuploader上传文件插件

引入css和js:

view层:

  • html
选择图片
  • js

controller层:

file('file');

        $allowed_extensions = ["png", "jpg", "gif", "jpeg", "bmp"];
        if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
            return json_encode(['error' => 'You may only upload png, jpg or gif or jpeg or bmp.']);
        }

        $destinationPath = 'storage/uploads/'.date('Ymd').'/'; //public 文件夹下面建 storage/uploads 文件夹
        $extension = $file->getClientOriginalExtension();
        $fileName = md5(microtime(true)).'.'.$extension;
        $file->move($destinationPath, $fileName);

        return json_encode(['type' => $extension , 'url' => $http_type.$_SERVER['HTTP_HOST'].'/'.$destinationPath.'/'.$fileName , 'name' => $fileName]);
    }
}

你可能感兴趣的:(laravel调用webuploader插件)