1

I have a form that uploads two files. If I upload small files it works well but if I upload large files gives me this warning:

Warning: POST Content-Length of 31996010 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

I have read some article that tell to change the php.in upload_max_filesize and post_max_size. I change both to 200M and restart mamp.

If I go to the phpinfo file I saw both parameters with 200M, so it changes that but the warning continuous and don't upload the files.

My code to upload is that:

$coverName = uniqid($catalogue->companyId.'_C'.$catalogue->ref.'_');
    $fileName = uniqid($catalogue->companyId.'_P'.$catalogue->ref.'_');
    $coverExtension = $request->file('cover')->getClientOriginalExtension();
    $pdfExtension = $request->file('pdf')->getClientOriginalExtension();
    $destination = '/storage/app/public/uploads';

    $request->file('cover')->move($destination, $coverName.".".$coverExtension);
    $request->file('pdf')->move($destination, $fileName.".".$pdfExtension);

.htaccess file:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Do I have to change some definition in laravel?

Thank you

user3242861
  • 1,839
  • 12
  • 48
  • 93
  • 1
    Have you tried to run `php -i` and checked the correct .ini file for `Loaded Configuration File` (NOT just the `Configuration File`) – Daniel Jul 19 '17 at 18:17
  • Works! Thank you @Daniel – user3242861 Jul 19 '17 at 18:26
  • Glad to be of help. I've added my comment as a question to it hopefully can help others with the same problem. Feel free to accept my answer :) – Daniel Jul 19 '17 at 19:08
  • Possible duplicate of [PHP change the maximum upload file size](https://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size) – Kyslik Jul 19 '17 at 19:49
  • I faced the same problem. I tried changing the values for both settings, but still, it didn't work. Although, the changes were reflected in `phpinfo()` but, they never came in effect. Because, it turned out, when ever I was opening the `php.ini` file to edit (using `wampserver` context menu) it was opening from the `apache` directory instead of the `php` directory. – Mr.Singh Sep 19 '20 at 15:17

2 Answers2

1

From the error it is clear that the max size is still set to 8M. If your values are indeed correct in php.ini, double check that they are not being overridden somewhere else.

You should check:

  • php.ini
  • .htaccess
  • Other apache/nginx config files

If you can't find where it is being set, you could search your system for 8M which might locate the file in which the value is set.

EDIT: It may prove useful to dig into the ValidatePostSize middleware where the PostTooLargeException is thrown and attempt some debugging there.

Do I have to change some definition in laravel?

No, you can see that the ValidatePostSize middleware compares $request->server('CONTENT_LENGTH') against ini_get('post_max_size').

Jim Wright
  • 5,905
  • 1
  • 15
  • 34
  • When I search for 8M shows me this in php.in... memory_limit = 128M ; Maximum amount of memory a script may consume (8MB) @JimWright – user3242861 Jul 19 '17 at 18:11
1

Changing upload_max_filesize and post_max_size in your php.ini should solve your problem.

Make sure you're changing the correct PHP file - if you run php -i (which is a way to run phpinfo() in a command line environment) you'll see both a Configuration File and a Loaded Configuration File.

Make sure you use the Loaded Configuration File, and not the other one.

Daniel
  • 10,641
  • 12
  • 47
  • 85