我的视图文件的表单部分是:
<form action="/admin/sliders" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="row">
<div class="col-sm-3 form-group">
<h4 class="slide">Slide photo name</h4>
</div>
<div class="col-sm-8 form-group">
<input class="form-control inbox-del" id="slide_name" name="slider_name" placeholder="Add slide name" type="text">
</div>
</div>
<div class="row">
<div class="col-sm-3 form-group">
<h4 class="slide">Add photo for slide</h4>
</div>
<div class="col-sm-6 form-group slide">
<input type="file" id="slider_link" name="slider_link" placeholder="Add a photo" >
</div>
<div class="col-sm-2 form-group">
<button class="btn btn-primary inbox-del pull-right"> Add Slider </button>
</div>
</div>
</form>
控制器文件如下:
public function store(Request $request){
$image = $request->file('image');
$filename = time().$image;
$gallery = new Slider;
$gallery->slider_name= $request->slider_name;
$gallery->slider_link = $filename;
$gallery->save();
$request->slider_link->move(public_path('uploaded'),$gallery->slider_name);
return $request->slider_link;
}
我收到错误: FatalErrorException
在null 上调用成员函数move()。所有文本数据都插入到数据库中。但图像未放在uploaded
目录中。
答案 0 :(得分:1)
您需要使用location ^~ /(images|js|css) {
函数来获取文件名。
getClientOriginalName