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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:25:05  来源:igfitidea点击:

$_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size

phpfileuploadsize

提问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_filesizeand post_max_sizesettings) and it fails with error code 1: which says is:

我尝试上传一个 5MB(小于两者upload_max_filesizepost_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_sizein "php.ini"

您还必须post_max_size在“php.ini”中设置

回答by yasin

upload_max_filesize = 7M

Here the value is like 7Mor 10Mbut not MB.

这里的值是 like 7Mor 10Mbut 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_filesizedirective 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 KeepAliveTimeouthigher than the 5seconds 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 Editorand update the value of upload_max_filesize.

转到 WHM->Service Configuration->PHP Configuration Editor并更新 的值upload_max_filesize