Uploadify: show error message from HTTP response

Solution 1:

Take a look at these two posts in the uploadify forum on how to handle errors

onError to display what's happening and Upload script error reporting

there is a lot of useful info in there ..

Update

The following seems to do the trick for me ..

'onComplete': function(a, b, c, d, e){
                    if (d !== '1')
                        {
                        alert(d);
                        }
                    else
                        {
                        alert('Filename: ' + c.name + ' was uploaded');
                        }
                  }

coupled with this version of the uploadify script

<?php

    if (!empty($_FILES)) 
    {
        $tempFile = $_FILES['userfile']['tmp_name'];

        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
        $targetFile =  str_replace('//','/',$targetPath) . $_FILES['userfile']['name'];

        move_uploaded_file($tempFile,$targetFile);

        switch ($_FILES['userfile']['error'])
        {     
            case 0:
             $msg = ""; // comment this out if you don't want a message to appear on success.
             break;
            case 1:
              $msg = "The file is bigger than this PHP installation allows";
              break;
            case 2:
              $msg = "The file is bigger than this form allows";
              break;
            case 3:
              $msg = "Only part of the file was uploaded";
              break;
            case 4:
             $msg = "No file was uploaded";
              break;
            case 6:
             $msg = "Missing a temporary folder";
              break;
            case 7:
             $msg = "Failed to write file to disk";
             break;
            case 8:
             $msg = "File upload stopped by extension";
             break;
            default:
            $msg = "unknown error ".$_FILES['userfile']['error'];
            break;
        }
    }
    if ($msg)
        { $stringData = "Error: ".$_FILES['userfile']['error']." Error Info: ".$msg; }
    else
        { $stringData = "1"; } // This is required for onComplete to fire on Mac OSX
    echo $stringData;
?>

Solution 2:

Unfortunately the onUploadError event does not have access to the reponse body. You'll have to return 200 status and handle the errors in onUploadSuccess as far as I'm aware.

Here's how I'm doing it:

'onUploadSuccess' : function(file, data, response) {
            var responseObj = JSON.parse(data);
            if(responseObj.error_message)
            {
                $("#" + file.id).hide();   // this will hide the misleading "complete" message..
                alert(responseObj.error_message);
                return;
            }
        }

Or better yet you could replace the "complete" message with your error message like so:

 'onUploadSuccess' : function(file, data, response) {
            var responseObj = JSON.parse(data);
            if(responseObj.error_message)
            {
                $("#" + file.id).find('.data').css('color', 'red').html(' - ' + responseObj.error_message);
                return;
            }
            console.log(file, data, response);
        }

Solution 3:

I've had the same problem. after search for hours I found the problem. I have set "proxy server" in my "internet Options->Lan setting" , and when I returned it to default state, uploadify worked again.