php 覆盖 upload_max_filesize

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

overriding upload_max_filesize

phpfileupload

提问by sanders

I am trying to override my upload_max_filesizein php but I still get the value which is in my php.ini file which is 2 mb.

我正在尝试覆盖我upload_max_filesize的 php,但我仍然得到 php.ini 文件中的值,该值是 2 mb。

ini_set('upload_max_filesize','30M');
ini_set('post_max_size','30M');
echo("<br>".ini_get('upload_max_filesize')."<br>");

回答by Paul Dixon

Those settings are not going to have any effect when set via ini_set.

通过ini_set.

The reason is that PHP needs those values beforeyour script is even executed. When an upload occurs, the target script is executed when the upload is complete, so PHP needs to know the maximum sizes beforehand.

原因是 PHP脚本执行之前就需要这些值。当上传发生时,目标脚本会在上传完成时执行,因此 PHP 需要事先知道最大大小。

Set them in php.ini, your virtual host config, or in a .htaccessfile. A typical .htaccessfile would look like this:

将它们设置在php.ini、您的虚拟主机配置或.htaccess文件中。典型的.htaccess文件如下所示:

php_value post_max_size 30M
php_value upload_max_filesize 30M