views:

41

answers:

2

The problem is that I want to check if the file is too large to upload so that I can display a relevant error message, but when the file is larger than upload_max_filesize in php.ini it seems to be only displaying a 0.

Why is this happening? How can I test that the file is too large to give a relevant error?

+1  A: 

the fact that the file is present and saying 0 indicates that an error occurred... usually it's over the filesize limit. That's the relevant error.

edit: As the commenter below mentions, the relevant error is on $_FILES['userfile']['error'].

Mike Sherov
No. The relevant error is on $_FILES['userfile']['error']
Vinko Vrsalovic
Of course! How could I have been so blind, thanks :)
Atomix
@Atomix: Why did you accept a wrong answer? :)
Vinko Vrsalovic
It worked. It made logical sense at the time
Atomix
+4  A: 

See http://php.net/manual/en/features.file-upload.errors.php

Relevant excerpt:

Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success.

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

Vinko Vrsalovic