Please be aware that this is an old post, more than one year old, so you might need to look for an updated version of this article either on this site or using your favourite search engine.
Yesterday Jeff Madsen has sent a small Laravel tip which address how you can validate
the post size for your uploaded data via Laravel middleware called
Even though the solution is valid when you have no control over your server, but when you do, you should fix the base of the problem which is your web server (in my case its Nginx ).
Normal when you upload a file, the process looks like this :
- The user request the website
- The Server get the request first and forward it to PHP process.
- PHP process do the magic and response back to the Server.
And the data get back from 3 to 1 .
Now as I said the solution which was provided solve the problem at the PHP processes level not at the Web server, at the end the data need to go through the server first.
In nginx documentation we have a core module which control the size of the data which the client can send through the server, the default size is 1Mb, so to fix this problem you need to do the following:
- edit the file
/etc/nginx/nginx.confand make sure that the value for
client_max_body_sizeis big enough like:
- edit your
php.inifile to make sure that you have setup the upload size and memory with big values like :
memory_limit = 128M post_max_size = 100M upload_max_filesize = 200M
lastly you need to restart nginx.
now just a small note, you will need to adjust the values based on your needs, there are no magic values which can solve your issue here.
If you find that this information is incorrect, please let me know via email z[At]zah.me. I'll be happy to get more information about this topics from experienced people out there.
PS: as usual, since english is not my mother language, you might find some errors, so if you do let me know and I will be happy to fix it.