开发者

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

开发者 https://www.devze.com 2023-01-26 17:48 出处:网络
I have a simple upload form with: enctype=\"multipart/form-data\"/> and input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"5900000\" />

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:

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

I tr开发者_如何学运维y 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:

UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

Anyone has a clue what is going on?


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.



You also have to set the post_max_size in "php.ini"


upload_max_filesize = 7M

Here the value is like 7M or 10M but not MB.

Use phpinfo() again to check what value actually got applied.

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

<?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.


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.

For example:

KeepAliveTimeout 300

You can find this property in /etc/apache2/apache2.conf


goto WHM->Service Configuration->PHP Configuration Editor and update the value of upload_max_filesize.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号