Laravel 5.5文件上传请求 - > hasFile返回null
问题描述:
我一直在寻找一个小时的解决方案。试图把enctype作为最有建议,但仍然没有解决方案。Laravel 5.5文件上传请求 - > hasFile返回null
HTML
<form action="/backportal/knowledge/postlist" method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="exampleInputEmail1">Title</label>
<input type="text" class="form-control" placeholder="Title" name="title">
<label for="exampleInputEmail1">Short Description</label>
<input type="text" class="form-control" placeholder="Short description" name="short_desc">
<label for="exampleInputEmail1">Long Description</label>
<input type="text" class="form-control" placeholder="Short description" name="long_desc">
</div>
<div class="form-group">
<label for="exampleInputFile">Image</label>
<input type="file" class="form-control-file" name="image">
</div>
<br/>
<button type="submit" class="btn-primary">Submit</button>
</form>
控制器
public function postlist(Request $request){
if ($request->hasFile('image')) {
echo 'yes';
}else{
echo 'no';
}
}
答
在Laravel 5.5,你应该使用file:
public function postlist(Request $request){
if ($request->file('image')) {
echo 'yes';
}else{
echo 'no';
}
}
+0
好的,工作。但是,现在当我尝试写入文件时,它是一个空的图像。 –
+0
你刚刚通过更新我的答案完全改变了问题的内容。不是很酷的兄弟。你应该提出另一个问题来解决另一个问题。 –
它在标题 –
在你的PHP设置中启用文件上传:' ''file_uploads =开'''。你在使用什么平台? –