Home » Php » php – $_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

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 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:

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?

How to&Answers:

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.

Answer:


You also have to set the post_max_size in “php.ini”

Answer:

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.

Answer:

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

Answer:

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