Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does it mean when $_FILES is empty?

I am working on a PHP upload script and when testing my error checks, I attempted to upload a 17MB TIFF file. When I do this the $_FILES array is empty. The script works fine for what I need it to do, which is to upload JPEG files. My solution is to test if $_FILES is empty or not before continuing with the upload script.

Can anybody explain why $_FILES is empty when a TIFF is attempted to be uploaded? Is my solution, to check if $_FILES is empty or not, an okay one?

Does this have something to do with settings in php.ini?

Just to clarify

I was checking that $_FILES was empty using the following:

if(empty($_FILES))
{
    die('$_FILES is empty.');
}
like image 387
Mike Moore Avatar asked May 25 '10 04:05

Mike Moore


People also ask

What does it mean when a file is empty?

In general, empty refers to anything containing nothing. For example, with a computer, an empty file is a file with no data and is 0 bytes. An empty folder is a folder with no other files or folders.

What is the use of $_ files in PHP?

$_FILES is a super global variable which can be used to upload files. Here we will see an example in which our php script checks if the form to upload the file is being submitted and generates a message if true. Code of files.

Is PHP file empty?

PHP empty() FunctionThe empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.


2 Answers

Yes, upload_max_filesize controls max upload size, which the TIFF file most likely exceeded. The default is 2M. You can test with:

echo ini_get("upload_max_filesize");

EDIT: Actually, the exact cause is more likely post_max_size, which is always >= upload_max_filesize: "If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty."

like image 109
Matthew Flaschen Avatar answered Nov 11 '22 19:11

Matthew Flaschen


You should check to see if $_FILES['file']['error'] is equal to 0. This indicates a "success".

If your files array is empty, it might be due to some other problem, like not including the enctype.

Try doing var_dump($_FILES) and viewing the contents...

EDIT: I know you can set the max filesize in the php.ini file, but I am not sure if that will give you an empty files array. I think you will just get an error.

like image 33
Mitch Dempsey Avatar answered Nov 11 '22 20:11

Mitch Dempsey