user3555081 user3555081 - 6 months ago 11
PHP Question

Laravel form not returning input when I add 'files'=>true

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.

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.

Answer

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.

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.

The solution is to increase the value for post_max_size, and/or also, upload_max_size or even memory_limit.