Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 376
mgpepe Avatar asked Nov 23 '10 11:11

mgpepe


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

like image 69
Pekka Avatar answered Nov 05 '22 19:11

Pekka



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

like image 8
Lawrence Avatar answered Nov 05 '22 19:11

Lawrence


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.

like image 5
yasin Avatar answered Nov 05 '22 21:11

yasin