Uploadify:显示PHP错误

How can I send errors caused in back-end PHP file of Uploadify to the uploading form? Right now when I have an error to report to the user from PHP I just echo and it goes to the onComplete method of Uploadify and alerts the user. Please see below:

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
    move_uploaded_file($tempFile,$targetFile);
}

if ($error) // I want to show this error on uploading form page.
    {
    echo "Some error";
    } 
else
    {   
    echo '1';
    }
?>

and I get the error like:

'onComplete': function(a, b, c, data, e){
                                alert(data); 
            }
  1. The problem is that I want to get Only error, but it will print "1" if there is no error. I want to print only if there is any error, otherwise dont print 1.
  2. How can i append the error data on the page instead of alert?

Thanks

Have PHP echo 1 if success and an error message if not. Then just check the response back is 1 or something else.

'onComplete': function(a, b, c, data, e){
  if (data == '1') {
      alert('ok!');
   }
   else {
      alert('Error: ' + data);
   } 
 }

try this:

if ($error) 
    {
    echo "error:".$error;
    } 

Uploadify has an OnError callback.

Like this:

'onError' : function(event, ID, fileObj, errorObj) {
       alert(errorObj.type+"::"+errorObj.info);
       }    

This will only alert if there is an error with the upload. This specific code will let you know the error type and the information about the error

here is the link to the Uploadify documentation about this: onError

There is a guy who have fixed this problem, check the following link:

http://www.uploadify.com/forum/#/discussion/9139/custom-errors-dont-register-says-completed-instead-/p1

it helped me out big time!

From the Uploadify documentation:

Anything that is echoed in the uploadify.php script is accessible via the onUploadSuccess event as the second argument (data).

The uploadify.php File

$targetFolder = '/uploads'; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);
    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo $targetFolder . '/' . $_FILES['Filedata']['name'];
    } else {
        echo 'Invalid file type.';
    }
}

The Uploadify Call

$('#file_upload').uploadify({
    // Some options
    'onUploadSuccess' : function(file, data, response) {
        alert('The file was saved to: ' + data);
    }
});