laravel 照亮\Http\Exceptions\PostTooLargeException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48601191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:20:17  来源:igfitidea点击:

Illuminate \ Http \ Exceptions \ PostTooLargeException

phplaravellaravel-5

提问by Prashant Gaurav

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?

我已经配置了 php.ini 文件(post_max_size=10240M),但它仍然抛出 PostTooLargeException。如何在 Laravel 5.5 中增加上传和下载限制?

回答by cyber8200

First, check your php version

首先,检查您的php版本

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

如果你的 php 版本是 7.2

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

打开这个文件 /etc/php/7.2/fpm/php.ini

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

将这 2 个字段更新为足够大的内容。前任。1024M或者2048M

post_max_size = 1024M                                                                                                            
upload_max_filesize = 1024M  

Restart the php

重启php

service php7.2-fpm restart

Done ?

完毕 ?

回答by Md Johirul Islam

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

您可以尝试在php.ini文件中使用以下代码来增加内存限制。

 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

您可能还有兴趣阅读https://laracasts.com/discuss/channels/servers/interventionimage-memory-limit?page=1

回答by Kaushik shrimali

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-posttoolargeexceptionexception

1) 如果您从 php.ini 更改 post_max_size 并重新启动 apache 服务器,但在没有得到正确响应之后,则您有临时解决方案。

处理illuminate-http-exceptions-posttoolargeexception异常

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

回答by Tumelo Mapheto

First, check your PHP version.

首先,检查您的 PHP 版本。

php -v

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

下面的命令将打印您的服务器正在使用的 php.ini 文件的路径。

php -i | grep php.ini

Next.

下一个。

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

The values of post_max_size, upload_max_filesizeand memory_limitby default have the value of 8M, 2M, and 128Mrespectively.

的值的post_max_size的upload_max_filesizememory_limit的默认具有的值8M2M,和128M分别。

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.

对于“高负载站点”,安装并运行 FPM 很有用。

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

Finally, restart your web server.

最后,重新启动您的 Web 服务器。

sudo service apache2 restart