1
votes

I have the following problem in Laravel.

I would like to upload a file through a form. But for some reason if the file is larger than around 2100 KB, the validation fails, and says that the file is 'required' and I did not provide it.

I've read numerous articles, that this can be because of php.ini settings. On my server they are the following:

upload_max_filesize 64M
post_max_size 64M

These values are copied from the output of phpinfo(), so they are in effect.

And despite this, the upload fails even for a 2 MB file. Do you have any ideas what I could check/set to solve this?

I am using laravel 5.2, and PHP 7.

3

3 Answers

1
votes

Check which server software you are using. Nginx for instance has it's own limit (default set to 1MB I believe). Apache might have it too. Consult the respective manuals for those packages on how to configure them. Or if you're using shared hosting, contact support to see if they can increase the limit.

Though this isn't a really scalable solution. Next time you might want to upload a 100MB file, and you probably don't want to allow 100MB requests on your servers. A better approach would be to split the file in smaller chunks in the frontend, with JavaScript, and submit them as parts of the same upload, then recombine the parts on the server once the file is completely uploaded. Beware of additional checks you'll have to do here though.

0
votes

You might want to incorporate the following into your own code:

<?php
//--- this tries to override the default of only 2M file uploads.
ini_set("upload_max_filesize","25M");
ini_set("max_execution_time",600); //--- 10 minutes
ini_set("post_max_size","35M");
ini_set("file_uploads","On");
?>
0
votes

In my case, it was HDD space issue. not enough space to store the file. Laravel should handle it with proper message, instead of indicating user didn't upload anything.