jquery插件'uploadify' - 从上传脚本返回响应的方法?

Bre*_*ett 5 jquery jquery-plugins uploadify

我的标题代码:

$(document).ready(function() {
    $('#sampleFile').uploadify({
        'uploader': 'include/uploadify/uploadify.swf',
        'script': 'add_list.php',
        'scriptData': {'mode': 'upload'},
        'fileDataName': 'sampleFile',
        'folder': '/work/avais/bizlists/lists',
        'cancelImg': 'include/uploadify/cancel.png',
        'queueID': 'sampleQueue'
    });
});
Run Code Online (Sandbox Code Playgroud)

我可以在"add_list.php"文件中执行的AFAIK是通过将文件移动到最终目录来完成上传过程; 我不认为有什么办法可以像错误一样'回复'吗?

如果我还可以使用这个文件来禁止某些字符或者如果出现某种问题则返回错误,那会很好,但我不认为有?

我想我可以删除任何不好的字符,但知道我是否能以某种方式返回响应会很有用吗?

Lor*_*nzo 7

您可以向上传脚本添加一些事件处理程序,以检查完整操作和错误

$('#sampleFile').uploadify({
        'uploader': 'include/uploadify/uploadify.swf',
        'script': 'add_list.php',
        'scriptData': {'mode': 'upload'},
        'fileDataName': 'sampleFile',
        'folder': '/work/avais/bizlists/lists',
        'cancelImg': 'include/uploadify/cancel.png',
        'queueID': 'sampleQueue'

    onComplete: function (event, queueID, fileObj, response, data) {
        // A function that triggers when a file upload has completed. The default 
        // function removes the file queue item from the upload queue. The 
        // default function will not trigger if the value of your custom 
        // function returns false.
        // Parameters 
        //    event: The event object.
        //    queueID: The unique identifier of the file that was completed.
        //    fileObj: An object containing details about the file that was selected.
        //    response: The data sent back from the server.
        //    data: Details about the file queue.
    },

    onError: function (event, queueID, fileObj, errorObj) {
        // A function that triggers when an error occurs during the upload process. 
        // The default event handler attaches an error message to the queue item 
        // returning the error and changes it's queue item container to red.
        // Parameters 
        //    event: The event object.
        //    queueID: The unique identifier of the file that was errored.
        //    fileObj: An object containing details about the file that was selected.
        //    errorObj: An object containing details about the error returned.
    }

});
Run Code Online (Sandbox Code Playgroud)

因此,由于onComplete函数将从服务器端脚本发回响应,因此您可以向客户端返回响应,然后在事件处理程序内解析响应.

有关更多详细信息,查看Uploadify文档

希望能帮助到你