php 即使upload_max_size 大于文件大小,$_FILE 上传大文件也会出现错误1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4255617/
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
$_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size
提问by mgpepe
I have a simple upload form with:
我有一个简单的上传表单:
enctype="multipart/form-data"/>
and
和
input type="hidden" name="MAX_FILE_SIZE" value="5900000" />
And the following settings, that are applied (checked through phpini()) in php.ini:
以及在 php.ini 中应用的以下设置(通过 phpini() 检查):
upload_max_filesize = 7MB
memory_limit = 64M
post_max_size = 8MB
I try to upload a file that is small - 500k and it goes through
我尝试上传一个很小的文件 - 500k 并且它通过
I try to upload a file that is 5MB (smaller than both upload_max_filesize
and post_max_size
settings) and it fails with error code 1: which says is:
我尝试上传一个 5MB(小于两者upload_max_filesize
和post_max_size
设置)的文件,但它失败并显示错误代码 1:它表示:
UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_INI_SIZE 值:1;上传的文件超过了 php.ini 中的 upload_max_filesize 指令。
Anyone has a clue what is going on?
任何人都知道发生了什么?
回答by Pekka
I think this is because of a typo. Instead of
我认为这是因为打字错误。代替
upload_max_filesize = 7MB
it should read
它应该读
upload_max_filesize = 7M
use phpinfo()
again to check what value actually gets applied.
phpinfo()
再次使用以检查实际应用的值。
回答by Lawrence
You also have to set the post_max_size
in "php.ini"
您还必须post_max_size
在“php.ini”中设置
回答by yasin
upload_max_filesize = 7M
Here the value is like 7M
or 10M
but not MB
.
这里的值是 like 7M
or 10M
but not MB
。
Use phpinfo()
again to check what value actually got applied.
phpinfo()
再次使用以检查实际应用了什么值。
Use the code below to understand what the problem is. If file size is the problem, it simply prints out put as exceeds the upload_max_filesize
directive in php.ini
使用下面的代码来了解问题所在。如果文件大小是问题,它只是简单地打印输出超出upload_max_filesize
指令php.ini
<?php
$error_types = array(
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
'The uploaded file was only partially uploaded.',
'No file was uploaded.',
6 => 'Missing a temporary folder.',
'Failed to write file to disk.',
'A PHP extension stopped the file upload.'
);
// Outside a loop...
if ($_FILES['userfile']['error'] == 0) {
// here userfile is the name
// i.e(<input type="file" name="*userfile*" size="30" id="userfile">
echo "no error ";
} else {
$error_message = $error_types[$_FILES['userfile']['error']];
echo $error_message;
}
?>
By this we can easily identify the problem. We can also use switch(){ case }
to print the above error messages.
这样我们就可以很容易地找出问题所在。我们也可以switch(){ case }
用来打印上面的错误信息。
回答by pdschubert
Here is a big mistake I've done:
这是我犯的一个大错误:
If you want to upload really big files, you have to set KeepAliveTimeout
higher than the 5
seconds default value.
如果你想上传非常大的文件,你必须设置KeepAliveTimeout
高于5
秒默认值。
For example:
例如:
KeepAliveTimeout 300
You can find this property in /etc/apache2/apache2.conf
您可以在 /etc/apache2/apache2.conf
回答by nisam
goto WHM->Service Configuration->PHP Configuration Editor
and update the value of upload_max_filesize
.
转到 WHM->Service Configuration->PHP Configuration Editor
并更新 的值upload_max_filesize
。