1
votes

I am out of explanation for the apparently very basic problem of "The file is too large. Allowed maximum size is 2097152 bytes." on Symfony.

In my php.ini, I have set the 'upload_max_filesize' to '512M' and the 'post_max_size' to '1024M'.

In my entity for which i am trying to upload this file, i have set the 'maxSize' assert attribute like this:

/**
 * @ORM\Column(type="string", length=255)
 *
 * @Assert\File(
 *     maxSize = "1024M",
 *     mimeTypes = {"application/xml"}
 * )
 */
private $fileName;

When i remove the 'maxSize' attribute in my entity, the message only changes to "The file is too large. Allowed maximum size is 2 MiB."

The file i am trying to upload is 7,203Ko It works nicely when i upload a file inferior to 2Mo.

Any idea?

2
Can you please check phpinfo(); that your php.ini working and your changes initialized on there?bl4cksta
There you go! It is set at 2Mo on my phpinfo. But...why the hell?!user2183282
So, i am using WAMP. When i try to edit the php.ini file via the WAMP menu (icon => PHP => php.ini OR icon => PHP => PHP configuration => upload_max_filesize / post_max_size), it actually edits the file located in C:\wamp64\bin\apache\apache2.4.27\bin\php.ini BUT my phpinfo() uses the one located in C:\wamp64\bin\php\php7.1.9\php.ini Weird. But anyway, whether i change one or the other, it doesn't work! I didn't forget to restart WAMP everytime i made some changes.user2183282

2 Answers

1
votes

I ve been through the same problem, this is how i fixed it:

Run phpinfo() to find where the php.ini file is.
(There was no Loaded configuration File used in my case)

Configuration File (php.ini) Path: /etc   
Loaded Configuration File:        (none)

Go to the /etc folder where you should found a php.ini.default file. Copy the php.ini.default and rename it to php.ini using the following command:(sudo is for mac users)

sudo cp php.ini.default  php.ini 

Open the newly created file with vim (or any editor) to edit it.

vim php.ini

Change this line to the size you need:

upload_max_filesize = 20M 

save and exit.
relaunch you server, it must be working

0
votes

Got it!

Actually 2 php.ini are "used". When using the WAMP process to edit the php.ini file (click on icon + php + php.ini OR click on icon + PHP + PHP configuration + whateveryouwannachange), it is using the one located at "C:\wamp64\bin\apache\apache2.4.27\bin\php.ini"

When i use phpinfo() to locate the php.ini file used, it shows me the one with the path "C:\wamp64\bin\php\php7.1.9\php.ini"

Why is it different? No idea.

I could do whatever changes i wanted, it was never taken into account, because... i am using the "symfony/web-server-bundle" library as a web-server and i have to close the server every time i update the php.ini file so that it works.