使用swfupload处理错误

时间:2012-01-03 15:29:34

标签: error-handling swfupload

我不想这样做。我从下载包中找到的样本开始,根据我的需要进行编辑。 我在php服务器文件脚本中进行了扩展验证,因此如果扩展名不在白名单中,则脚本将退出并显示错误。 我不知道如何获得自定义消息的工作。

有php功能

function HandleError($message) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $message;
}

但这只返回500而不是$ message!这是js uploadError()

function uploadError(file, errorCode, message) {
try {
    var progress = new FileProgress(file, this.customSettings.progressTarget);
    progress.setError();
    progress.toggleCancel(false);

    switch (errorCode) {
    case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
        progress.setStatus("Errore upload: " + message);
        this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
        progress.setStatus("Upload fallito.");
        this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.IO_ERROR:
        progress.setStatus("Errore Server (IO)");
        this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
        progress.setStatus("Errore Security");
        this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
        progress.setStatus("Limite upload superato.");
        this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
        progress.setStatus("File non valido.  Upload ignorato.");
        this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
        break;
    case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
        // If there aren't any files left (they were all cancelled) disable the cancel button
        if (this.getStats().files_queued === 0) {
            document.getElementById(this.customSettings.cancelButtonId).disabled = true;
        }
        progress.setStatus("Cancellato.");
        progress.setCancelled();
        break;
    case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
        progress.setStatus("Sospeso.");
        break;
    default:
        progress.setStatus("Errore non gestito: " + errorCode);
        this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
        break;
    }
} catch (ex) {
    this.debug(ex);
}

如果我注释掉header()函数,它会在进度条(yay)中显示错误,但会将其视为成功,而不是我必须对其进行错误处理。移除header() js脚本后,转到uploadSuccess而不是uploadError 文档非常难看,我找不到任何其他内容。

1 个答案:

答案 0 :(得分:3)

删除标题,然后在exit(0)之后添加echo $message。我认为这将解决问题。