标签:ora contents lex dmi 添加 src icon path back
图片上传控制器代码
// 文件上传方法
    public function upload(Request $request)
    {
        if ($request->isMethod(‘post‘)) {
            $file = $request->file(‘picture‘);
            // 文件是否上传成功
            if ($file->isValid()) {
                // 获取文件相关信息
                $originalName = $file->getClientOriginalName(); // 文件原名
                $ext = $file->getClientOriginalExtension();     // 扩展名
                $realPath = $file->getRealPath();   //临时文件的绝对路径
                $type = $file->getClientMimeType();     // image/jpeg
                // 上传文件
                $filename =  uniqid() . ‘.‘ . $ext;
                // 使用我们新建的uploads本地存储空间(目录)
                //这里的uploads是配置文件的名称
                $bool = Storage::disk(‘uploads‘)->put($filename, file_get_contents($realPath));
                exit(‘{"src":"‘ . $realPath . ‘"}‘);
            exit;
            }
        }
        return view(‘upload‘);
    }
上传路径配置
config>filestream.conf
// 新建一个本地端uploads空间(目录) 用于存储上传的文件
‘uploads‘ => [
            ‘driver‘ => ‘local‘,
            // 文件将上传到storage/app/uploads目录
            //‘root‘ => storage_path(‘app/uploads‘),
            // 文件将上传到public/uploads目录 如果需要浏览器直接访问 请设置成这个
            ‘root‘ => public_path(‘uploads‘),
 ],
图片上传前端代码
<form method="post" action="{{url(‘/blue_cross_admin/article/add‘)}}" enctype="multipart/form-data">
  <div class="form-group">
        <label for="file">标题插图:</label>
        <input type="file" name="picture" data-id="icon" class="img myfile"/><span  style="color: #cccccc">(图片大小为:355*300)</span>
   </div>
  <button type="submit" class="btn btn-primary">添加</button>
  <button type="reset" class="btn btn-danger">取消</button>
</form>
标签:ora contents lex dmi 添加 src icon path back
原文地址:https://www.cnblogs.com/catyxiao/p/11506241.html