-2

Why do I get an empty array instead of an error message when the upload files are exceeding the upload_max_filesize?

How can I get the error code number 1 like this below?

1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',

I have set my upload max limit to 2MB in .htaccess:

php_value post_max_size 2M
php_value upload_max_filesize 2M

My HTML form:

 <form class="form-submission" method="post" action="upload.php" enctype= "multipart/form-data">
    <input type="file" name="upload[]" id="input-file" multiple required>
    <button type="submit" class="btn btn-default no-gradient">Submit</button>
</form>

upload.php:

print_r($_FILES);

Then I try to upload files larger then 2MB. The result is:

Array ( ) 

No error coming from PHP. How can I make sure that PHP returns an error? Is it possible?

If I have this in my upload.php:

print_r($_SERVER['CONTENT_LENGTH']);

I get this:

6564878 // what is this mean??
Community
  • 1
  • 1
Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

0

The error is in $_FILES['userfile']['error']. You just have to check that this value is UPLOAD_ERR_INI_SIZE to detect if the file is bigger than the max size defined in your php.ini.

Hope it helps.

Anuj
  • 327
  • 1
  • 2
  • 14