Jump to content

$_FILES['file']['error'] question


Don E

Recommended Posts

Hey everyone, When a file that is being uploaded is larger than the upload file size allowed and the post max size in the php.ini, what is suppose to happen? Because when I test this, the status bar shows the file being uploaded(Chrome for instance shows the percent) and then once it's done, the page.... what it looks like is happening is it just refreshes... I thought maybe I can do this to get the error and to display an error but all I get is the 'refresh':

if($_FILES['img']['error'] == 1) // 1 means: The uploaded file exceeds the upload_max_filesize directive in php.ini.{     $this->error = 'Too big';     return; } 

http://www.php.net/manual/en/features.file-upload.errors.php Is it possible to have the file size checked before the whole thing is uploaded? I thought perhaps that's what I was able to do with the above as well. I noticed that the whole file is uploaded and THEN the check takes place. Thank you.

  • Like 1
Link to comment
Share on other sites

PHP doesn't have access to the file to check it before you upload it. There's a hidden input you're supposed to add in file upload forms specifying the size, but browsers don't validate that before the upload. Javascript also wouldn't be able to get the filesize prior to the upload. You use the upload error codes that you linked to in order to find out what happened with the upload.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...