0

我想在 laravel-6.2 中上传图片,但显示“E:\xampp\tmp\php3A05.tmp”文件不存在或不可读。我的控制器功能:

 $data = new Vedio();

        if($request->hasFile('image')){
            $files = $request->file('image');
            $extension = $files->getClientOriginalExtension();
            $fileName = str_random(5) . "-" . date('his') . "-" . str_random(3) . "." . $extension;
            $folderpath = 'public/'.'Vedio/' . date('Y') . '/';
            $image_url = $folderpath . $fileName;
            $files->move($folderpath, $fileName);
            // $data['topheadline_image'] = $image_url;
            $data->image = $image_url;
        }

        $data->link=$request->link;
        $data->title=$request->title;



        $data->status=0;
        $data->save();
        return redirect('/admin-dashbord/Vedio-list')->with('success','Data saved in database successfully');


      }

这是我的视图文件代码:这是我的视图文件代码:这是我的视图文件代码:这是我的视图文件代码:这是我的视图文件代码:

<form class="form-horizontal"action="{{url('/admin-dashbord/Vedio-post')}}" method="POST"enctype="multipart/form-data">
                @csrf
                    <fieldset>
                      <div class="control-group">
                        <label class="control-label" for="focusedInput">Title</label>
                        <div class="controls">
                          <input class="input-xlarge " id="" name="title"type="text" value="">

                        </div>
                      </div>

                      <div class="control-group">
                          <label class="control-label" for="focusedInput">Link</label>
                          <div class="controls">
                            <input class="input-xlarge " id="" name="link"type="text" value="">

                          </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="focusedInput">Image</label>
                            <div class="controls">
                              <input class="input-xlarge " id="" name="image"type="file" value="">

                            </div>
                          </div>




                      <div class="form-actions">
                        <button type="submit" class="btn btn-primary">Save changes</button>
                        <button class="btn">Cancel</button>
                      </div>
                    </fieldset>
                  </form>
4

2 回答 2

0

尝试更换

$folderpath = 'public/'.'Vedio/' . date('Y') . '/';

$folderpath = public_path().'/Vedio/'. date('Y'). $fileName;
$files->move($folderpath);
$data->image = $folderpath;

另外,我不知道你为什么将整个保存$folderpath在数据库中,你只能保存图像的名称,然后你可以做类似的事情

$image = public_path().'/Vedio/'.$data->image;
于 2019-10-20T11:27:55.313 回答
0

如果您的 Larval 6 版本不工作,那么您需要安装 Larval 6.2。检查您的 composer.json 一次。

于 2019-10-20T12:50:31.467 回答