views:

44

answers:

1

I have a php form that uploads files, and all files work good the limit size is set at 7340032 bytes (7Mbs) and it works ok, however when I try to upload an image larger than 500kbs when I echo the values of the first if:

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0){

it says the image size is 0 everytime, why would this happen? the php.ini values of post_max_size is 15M and of upload_max_filesize is 10M.

A: 

Checking if the uploaded file's size is non-zero is not the proper way to check if an upload succeeded. There's the ['error'] parameter in there for that. An incomplete upload would still have a non-zero size, but should not be processed. A better way to check is:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     if ($_FILES['userfile']['error'] !== UPLOAD_ERR_OK) {
        die("File upload error: {$_FILES['userfile']['error']}");
     }
     ... process file here ...
}

The error code constants are defined here.

Marc B
mm apparently I had to reboot because for some reason WAMP wasn't getting the new upload_max_filesize but what you posted actually helped me figure that out, thanks :)
Luis Armando