在 PHP 上更改 upload_max_filesize
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1122418/
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
Changing upload_max_filesize on PHP
提问by Ross
I'm using PHP 5.3.0 and have encountered something that might be a bug (in which case I'll report it) or might be me - so I'm asking to make sure.
我正在使用 PHP 5.3.0 并且遇到了一些可能是错误的东西(在这种情况下我会报告它)或者可能是我 - 所以我要求确保。
When running this code:
运行此代码时:
<?php
ini_set('upload_max_filesize', '10M');
echo ini_get('upload_max_filesize'), ", " , ini_get('post_max_size')
I end up with:
我最终得到:
2M, 8M
This is despite my php.ini setting these higher:
尽管我的 php.ini 将这些设置得更高:
upload_max_filesize = 10M
post_max_size = 10M
(occuring only once)
(只出现一次)
Because the error occurs after setting the value as well as it being set in php.ini I'm inclined to think it's a bug. Can anyone confirm or point me where I'm going wrong?
因为错误发生在设置值以及在 php.ini 中设置后,我倾向于认为这是一个错误。谁能确认或指出我哪里出错了?
Update: Looks like restarting Apache fixed this - I always thought it didn't need to be restarted if you changed php.ini.
更新:看起来重新启动 Apache 解决了这个问题 - 我一直认为如果你改变了 php.ini 就不需要重新启动它。
采纳答案by Rob
You can't use shorthand notationto set configuration values outside of PHP.ini. I assume it's falling back to 2MB as the compiled default when confronted with a bad value.
您不能使用速记符号在 PHP.ini 之外设置配置值。我认为它在遇到错误值时会回退到 2MB 作为编译默认值。
On the other hand, I don't think upload_max_filesizecould be set using ini_set(). The "official" liststates that it is PHP_INI_PERDIR.
另一方面,我认为upload_max_filesize不能使用ini_set(). 该“官方”列表中说,它是PHP_INI_PERDIR。
回答by karim79
Are you using a shared hosting provider? It could be master settings overriding anything you're trying to change. Have you tried adding those into your .htaccess?
您使用的是共享托管服务提供商吗?它可能是主设置覆盖了您尝试更改的任何内容。您是否尝试将这些添加到您的 .htaccess 中?
php_value upload_max_filesize 10M
php_value post_max_size 10M
回答by quid
Since I just ran in to this problem on a shared host and was unable to add the values to my .htaccess file I thought I'd share my solution.
由于我刚刚在共享主机上遇到这个问题并且无法将值添加到我的 .htaccess 文件中,我想我会分享我的解决方案。
I made an ini file with the values in it. Simple as that:
我制作了一个包含其中值的 ini 文件。就那么简单:
Make a file called ".user.ini" and add your values
制作一个名为“.user.ini”的文件并添加您的值
upload_max_filesize = 150M
post_max_size = 150M
Boom, problem solved.
砰,问题解决了。
回答by dwenaus
I got this to work using a .user.ini file in the same directory as my index.php script that loads my app. Here are the contents:
我使用与加载我的应用程序的 index.php 脚本位于同一目录中的 .user.ini 文件使其工作。以下是内容:
upload_max_filesize = "20M"
post_max_size = "25M"
This is the recommended solution for Heroku.
这是 Heroku 的推荐解决方案。
回答by Byron Whitlock
This can also be controlled with the apache configuration. Check the httpd.conf and/or .htaccess for something like the following:
这也可以通过 apache 配置来控制。检查 httpd.conf 和/或 .htaccess 中的类似内容:
php_value upload_max_filesize 10M
回答by Beachhouse
If you are running in a local server, such as wamp or xampp, make sure it's using the php.ini you think it is. These servers usually default to a php.ini that's not in your html docs folder.
如果您在本地服务器上运行,例如 wamp 或 xampp,请确保它使用您认为的 php.ini。这些服务器通常默认为不在您的 html docs 文件夹中的 php.ini。
回答by Sahan
This solution can be applied only if the issue is on a WordPress installation!
仅当问题出在 WordPress 安装上时,才能应用此解决方案!
If you don't have FTP access or too lazy to edit files,
如果您没有 FTP 访问权限或懒得编辑文件,
You can use Increase Maximum Upload File Size pluginto increase the maximum upload file size.
您可以使用增加最大上传文件大小插件来增加最大上传文件大小。
回答by Hassan Nemir
I've faced the same problem , but I found out that not all the configuration settings could be set using ini_set() function , check this Where a configuration setting may be set
我遇到了同样的问题,但我发现并非所有的配置设置都可以使用 ini_set() 函数进行设置,请检查 此处可以设置配置设置的位置
回答by sassman
if you use ini_set on the fly then you will find here http://php.net/manual/en/ini.core.phpthe information that e.g. upload_max_filesize and post_max_size is not changeable on the fly (PHP_INI_PERDIR).
如果您即时使用ini_set,那么您会在http://php.net/manual/en/ini.core.php 中找到例如upload_max_filesize 和post_max_size 无法即时更改的信息(PHP_INI_PERDIR)。
Only a php.ini, .htaccess or vhost config change seems to change these variables.
只有 php.ini、.htaccess 或 vhost 配置更改似乎会更改这些变量。
回答by Nishant Patel
You can use also in the php file like this
您也可以在这样的 php 文件中使用
<?php ini_set('upload_max_filesize', '200M'); ?>

