Testing file uploading

On a multi-user site, I’ve gotten feedback that some users have been having trouble uploading their profile images on one form, and documents on another. However, I haven’t been able to get specific information on the errors received. Can you all come up with a checklist of things to test? I can’t find any errors.

Many thanks E

This kind of thing is quite tricky to test.
What I generally do, when something that works for some people and not for others, is to email a var_dump($_FILES) whenever something is uploaded. That should contain the error code for the upload, which may give some more information. (alternatively, you could write the var_dump() to a text file and check it every now and then).

From there, you could try to find out why the upload is failing for some users.

Are you using a Flash uploader or a standard file input?

Have you tried something like this:


function file_upload_error_message($error_code) {
    switch ($error_code) { 
        case UPLOAD_ERR_INI_SIZE: 
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
        case UPLOAD_ERR_FORM_SIZE: 
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
        case UPLOAD_ERR_PARTIAL: 
            return 'The uploaded file was only partially uploaded'; 
        case UPLOAD_ERR_NO_FILE: 
            return 'No file was uploaded'; 
        case UPLOAD_ERR_NO_TMP_DIR: 
            return 'Missing a temporary folder'; 
        case UPLOAD_ERR_CANT_WRITE: 
            return 'Failed to write file to disk'; 
            return 'File upload stopped by extension'; 
            return 'Unknown upload error'; 

// Example
if ($_FILES['file']['error'] === UPLOAD_ERR_OK)
    // upload ok
    $error_message = file_upload_error_message($_FILES['file']['error']); 


(example above came from http://uk.php.net/manual/en/features.file-upload.errors.php about the sixth comment down)

$error_message would be passed along to your error and/or exception handler.

Have you checked php error log for any errors around the time the problem with uploads occurs?

Thank you, these comments are very helpful. Its a plain html uploader. They need javascript to work. That could be part of the issue. Javascript could be blocked on some computers.

SpacePhoenix I definitely have some of those validation catches but I’ll check to see if I have all of them. That’s a good list.

Thank You E

The blocking of javascript could well be the problem, ask the users concerned if they have javascript blocked.