4
votes

I have a Symfony2 form that is designed to accept an uploaded (xml) file and associate it with an entity. The entity to associate it with is selected from a Select element and so its ID is included in the POST data when the form is submitted.

Everything was working happily, but when I try to upload one particular xml file, Symfony claims that the POST data is empty - and so an error occurs as it cannot find the entity to associate the upload with.

In my controller action that handles the form submission, if I do this;

var_dump($request->request->all());

which returns "array: empty"

If I open the Symfony debug bar, it does say;

Request POST Parameters
No POST parameters 

But, when I monitor the request in Firebug, I can see the POST data and it is exactly what I'd expect. So, where has the POST data gone?

I'm using Symfony 2.3.9, by the way. All the XML files are valid XML, if that matters.

3
check your request file bag. $request->files->all() - guy_fawkes
Also check the post max and upload max limits. - Ramesh
var_dump( $request->files->all() ) gives "array empty" - very confusing! - Andrew Battye
Thanks Ramesh - it was "post_max_size" - it was set to 8M in php.ini and the file was 9MB! I thought I'd have gotten an error message, rather than all the POST data vanishing. - Andrew Battye

3 Answers

3
votes

I had a similar situation, that was resolved by increasing the maximum POST request size (post_max_size).

2
votes

Most likely it has to do with the PHP.ini settings and your max upload size.

I had a similar situation and files that are over 8 MB (the default value which you can change upon your needs) are not going to be found in $request->files and no error message is triggered.

0
votes

You should call the form like this:

<form action="{{ path('form_submit') }}" method="post" {{ form_enctype(form) }}>

if you use Twig