Laravel 中的 PostTooLargeException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43464593/
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 15:48:30  来源:igfitidea点击:

PostTooLargeException in Laravel

phplaravel

提问by Sankit Saini

I am getting the post too large exception when I try to upload files which are more than 2 MB in size and I've already tried everything like increasing the post_max_size and max_upload_size in php.ini file but I am still getting the same error. When I comment the handler function in validatepostsize.php file it shows token mismatch error:

当我尝试上传大小超过 2 MB 的文件时,我收到帖子太大异常,我已经尝试了所有方法,例如增加 php.ini 文件中的 post_max_size 和 max_upload_size,但我仍然遇到相同的错误。当我在 validatepostsize.php 文件中注释处理函数时,它显示令牌不匹配错误:

回答by AddWeb Solution Pvt Ltd

I think you can check the following parameters in your php.inifile like:

我认为您可以检查php.ini文件中的以下参数,例如:

upload_max_filesize = 40m
post_max_size = 50m

After restart your server like (apache)

像(apache)一样重启你的服务器

Hope this work for you!

希望这对你有用!

回答by MarkSkayff

One of the issues is that the Laravel PHP artisan servelocal development server uses the php.ini under PHP/CLI instead of under PHP/apache2

问题之一是LaravelPHP artisan serve本地开发服务器使用的是PHP/CLI下的php.ini,而不是PHP/apache2下

So if you are having this issue while developing with PHP artisan serve, go and fetch the php.inithat's under the /etc/php[version]/clifolder.

因此,如果您在使用 进行开发时遇到此问题PHP artisan serve,请获取该文件/etc/php[version]/cli夹下的php.ini

回答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

回答by always-a-learner

Actually I am looking for the same answer for the same issue. I have found out that the issue can be resolve with an edit of .htaccessfile.

实际上,我正在为同一个问题寻找相同的答案。我发现这个问题可以通过编辑.htaccess文件来解决 。

Add the below code in the file.

在文件中添加以下代码。

php_value upload_max_filesize 50M
php_value post_max_size 50M

This above two line will resolve the issue but if you are adding this much size then the line below give will save you from future issue. of like execution time expire and all.

以上两行将解决问题,但如果您添加这么多大小,那么下面给出的行将使您免于未来的问题。像执行时间到期等等。

php_value max_input_time 120
php_value max_execution_time 120