Illuminate \ Http \ Exceptions \ PostTooLargeException

后端 未结 4 842
眼角桃花
眼角桃花 2021-02-14 15:24

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?

相关标签:
4条回答
  • 2021-02-14 15:53

    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 ✅

    0 讨论(0)
  • 2021-02-14 15:59

    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

    0 讨论(0)
  • 2021-02-14 16:00

    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
    
    0 讨论(0)
  • 2021-02-14 16:10

    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
    
    0 讨论(0)
提交回复
热议问题