我的头部代码:
$(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'
});
});我在"add_list.php“文件中所能做的就是通过把文件移到最后的目录来完成上传过程;我不认为有任何方法可以像错误一样”返回一些东西“,对吧?
如果我还可以使用这个文件来禁止某些字符,或者在出现某种问题时返回错误,那就太好了,但我不认为有问题?
我想我可以去掉任何不好的字符,但是知道我是否可以以某种方式返回一个响应会很有用?
发布于 2010-11-01 06:39:11
您可以将一些事件处理程序添加到上载脚本中,以检查完整的操作和错误
$('#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.
}
});因此,由于onComplete函数将从服务器端脚本返回响应,因此您可以向客户端返回响应,然后在事件处理程序中解析该响应。
有关更多详细信息,请查看Uploadify documentation
希望能有所帮助
发布于 2010-11-01 07:38:04
在add_list.php文件中回显的任何内容都将作为响应发送到onComplete函数。因此,您可以执行以下操作:
$(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',
'onComplete' : function(event,ID,fileObj,response,data) {
alert(response);
}
});
});发布于 2010-11-03 18:55:30
如果你想要文件名,你“必须”使用(正确的方法) fileObj.name:
$(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',
'onComplete' : function(event,ID,fileObj,response,data) {
alert(fileObj.name);
}
});
});https://stackoverflow.com/questions/4065477
复制相似问题