Prashant Gaurav
Prashant Gaurav

Reputation: 189

Illuminate \ Http \ Exceptions \ PostTooLargeException

I already configured php.ini file (post_max_size=10240M), but it's still throwing PostTooLargeException. How to increase upload and download limit in Laravel 5.5?

Upvotes: 19

Views: 57152

Answers (7)

Tholscoa
Tholscoa

Reputation: 1

In my case it was php8.2 fpm php.ini issue. I was increasing the post_max_size and upload_max_size in /etc/php/8.2/cli/php.ini only and restarting my web server. Issue wasn't resolved.

But I later increased post_max_size and upload_max_size in /etc/php/8.2/cli/php.ini and restart php fpm service with the command

service php8.2-fpm restart

issue was solved then.

Upvotes: 0

Sujata Kalita
Sujata Kalita

Reputation: 49

1.first check your php version also php.ini file path by using this command

php -i | grep 'php.ini'

2.change the upload file size in php.ini

upload_max_filesize = 1024M 

3.reset apache server

sudo service apache2 restart

or you can change the size in .htaccess file

<IfModule mod_php7.c>
    php_value memory_limit 64M
</IfModule>

Upvotes: 0

bar5um
bar5um

Reputation: 912

For anyone using Valet:
I had to set post_max_size,upload_max_filesize and memory_limit in /etc/php/7.4/fpm/php.ini instead of /etc/php/7.4/cli/php.ini.

Upvotes: 1

Tumelo Mapheto
Tumelo Mapheto

Reputation: 565

First, check your PHP version.

php -v

The command below will print the path to the php.ini file that your server is using.

php -i | grep php.ini

Next.

sudo nano /etc/php/7.4/cli/php.ini

The values of post_max_size, upload_max_filesize and memory_limit by default have the value of 8M, 2M, and 128M respectively.

Search for those variables and change their values, whilst ensuring that the sizes follow the same ratio as the default values.

See example below:

post_max_size = 2G
upload_max_filesize = 1G
memory_limit = 3G

For "heavy-loaded sites", it is useful to have FPM installed and running.

sudo apt install php7.4-fpm -y
sudo service php7.4-fpm start

Finally, restart your web server.

sudo service apache2 restart

Upvotes: 18

Kaushik shrimali
Kaushik shrimali

Reputation: 1228

1) If you change the post_max_size from php.ini and restart the apache server but after does not get proper response then you have temp solution.

Handle the illuminate-http-exceptions-posttoolargeexception exception

public function render($request, Exception $exception)
{
    if ($exception instanceof \Illuminate\Http\Exceptions\PostTooLargeException) {
        return redirect()->back()->withErrors(['File size is too large']);
    }
    return parent::render($request, $exception);
}

and display the error in your view file

@if ($errors->any())
    @foreach ($errors->all() as $error)
                    <div class="alert alert-danger">{{ $error }}</div>
    @endforeach
@endif

Upvotes: 2

Md Johirul Islam
Md Johirul Islam

Reputation: 5162

You may try the following code in your php.ini file to increase the memory limit.

 ini_set('memory_limit','10240M');
 # Do your Intervention operations...

You may also be interested to read https://laracasts.com/discuss/channels/servers/interventionimage-memory-limit?page=1

Upvotes: 4

code-8
code-8

Reputation: 58672

First, check your php version

php --version 


PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

if your php version is 7.2

open this file /etc/php/7.2/fpm/php.ini

Update these 2 fields to something that big enough. Ex. 1024M or 2048M

post_max_size = 1024M                                                                                                            
upload_max_filesize = 1024M  

Restart the php

service php7.2-fpm restart

Done ✅

Upvotes: 33

Related Questions