无法在larvel-6中上载图像,显示“ E:\ xampp \ tmp \ php3A05.tmp”文件不存在或不可读

问题描述 投票:0回答:2

我想在larvel-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>
laravel image-uploading laravel-6.2
2个回答
0
投票

尝试替换

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

to

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

而且,我也不知道为什么将整个$folderpath保存在数据库中,您只能保存图像名称,然后才能执行类似的操作>]

$image = public_path().'/Vedio/'.$data->image;

0
投票

如果您的Larval 6版本无法正常工作,则需要安装Larval 6.2。一次检查您的composer.json。

© www.soinside.com 2019 - 2024. All rights reserved.