添加“文件”=> true 时,Laravel 表单不返回输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23189096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel form not returning input when I add 'files'=>true
提问by user3555081
I have a form looking like this:
我有一个看起来像这样的表格:
{{ Form::open(array('route' => 'notebook.store', 'files' => true)) }}
{{ Form::text('title', null, [
'class'=>'form-control',
'placeholder'=>'Title',
]) }}
<br>
{{ Form::text('description', null, [
'class'=>'form-control',
'placeholder' => 'Desc',
])}}
<br>
{{ Form::file('path') }}
<br>
{{ Form::submit('Save', [
'class' => 'btn btn-primary btn-lg pull-right'
]) }}
<br><br>
{{ Form::close()}}
The problem is that Input::all()
in my controller returns an empty array if that 'files'=>true
is in the form description, when I remove it, the problem goes away and Input::all()
returns the usual, expected input.
问题是,Input::all()
如果我的控制器'files'=>true
在表单描述中返回一个空数组,当我删除它时,问题就会消失并Input::all()
返回通常的预期输入。
Edit- I found out what the problem was. My server had terribly low post_max_size in php.ini, and apparently it clears all your post/get data if the file exceeds that limit.
编辑 - 我发现了问题所在。我的服务器在 php.ini 中的 post_max_size 非常低,如果文件超过该限制,它显然会清除您所有的 post/get 数据。
采纳答案by Rubens Mariuzzo
If you are not receiving any POST data, you have to check for the post_max_size
directive and comparing to how much POST data you are sending to the server.
如果您没有收到任何 POST 数据,您必须检查post_max_size
指令并与您发送到服务器的 POST 数据量进行比较。
As you already experienced, the behavior of having no post data is clearly described on the docs:
正如您已经体验到的,文档中清楚地描述了没有发布数据的行为:
If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. , and then checking if $_GET['processed'] is set.
如果 post 数据的大小大于 post_max_size,则 $_POST 和 $_FILES 超全局变量为空。这可以通过多种方式进行跟踪,例如通过将 $_GET 变量传递给处理数据的脚本,然后检查是否设置了 $_GET['processed']。
The solution is to increase the value for post_max_size
, and/or also, upload_max_size
or even memory_limit
.
解决方案是增加post_max_size
,和/或还有,upload_max_size
甚至 的值memory_limit
。
回答by Todor Todorov
Use this:
用这个:
{{ Form::open(array('route' => 'notebook.store', 'enctype' => 'multipart/form-data')) }}
For any reason this:
出于任何原因:
{{ Form::open(array('route' => 'notebook.store', 'files' => true)) }}
does not work!
不工作!
回答by thePHPHero
Its not working because you are adding files=>true to the route array:
它不起作用,因为您将 files=>true 添加到路由数组:
{{ Form::open(array('route' => 'notebook.store', 'files' => true)) }}
Instead try this
而是试试这个
{{ Form::model(array('route'=>array('notebook.store'),'files'=>true)) }}
回答by Md. Abu Taleb
{!! Form::open(['url' => 'notebook.store', 'method' => 'post', 'enctype' => 'multipart/form-data']) !!}
<div class="form-group">
{!! Form::file('logo', null, ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Upload', ['class' => 'btn btn-primary']) !!}