gpt4 book ai didi

jquery - Uploadify:如何从队列中删除已上传的项目

转载 作者:行者123 更新时间:2023-12-01 01:01:32 25 4
gpt4 key购买 nike

我正在尝试 Uploadify 来清除上传队列并删除上传的文件。问题是这样的。如果我上传 5 个文件(uploadLimit 为 5 组),它们会第一次上传。但是如果我使用这个清除队列:

<a class="button" href="javascript:jQuery('#attachment').uploadify('cancel', '*');">Clear Upload Queue</a>

它会从屏幕上直观地删除文件,但我仍然无法上传更多文件。我尝试使用:

jQuery('#attachment').uploadify('settings', 'uploadLimit', 5)onQueueClear但它不会重置 uploadLimit 。如何重置 uploadLimit队列被清除后?这是我的代码:

jQuery('#attachment').uploadify({
swf: '/javascript/uploadify/uploadify.swf',
uploader: '/javascript/uploadify/uploadify.php',
uploadFolder: 'temp',
uploadTime: UPLOAD_TIME,
uploadToken: UPLOAD_TOKEN,
cancelImage: '/javascript/uploadify/cancel.png',
fileTypeExts: '*.jpg; *.gif; *.png; *.jpeg; *.doc; *.docx; *.zip; *.pdf; *.xls; *.xlsx; *.JPG',
fileTypeDesc: 'Allowed Files',
auto: true,
multi: true,
removeCompleted: false,
simUploadLimit: 1,
fileSizeLimit: '3MB',
allowedFiles: '*.jpg; *.gif; *.png; *.jpeg; *.doc; *.docx; *.zip; *.pdf; *.xls; *.xlsx; *.JPG',
// allowedFiles: '*.cdt;*.con;*.doc;*.docx;*.dxd;*.gif;*.jpg;*.jpeg;*.key;*.lab;*.mov;*.mp4;*.m4v;*.pdf;*.png;*.pps;*.ppt;*.pptx;*.rst;*.txt;*.wmv;*.xls;*.xlsx;*.zip',
uploadLimit: 5,
width: 210,
height: 40,
buttonText: 'Click to Add Up to 5 Attachments',
buttonImage: '/images/content/mail/add-attachments.png',
onUploadStart: function (file) {
jQuery('.submit').attr('disabled', 'disabled');

if (parseInt($.cookie('size')) > 0) {
$.cookie('size', parseInt($.cookie('size')) + file.size);
} else {
$.cookie('size', file.size);
}

if (parseInt($.cookie('size')) > 30000000) {
alert('You have exceeded the maximum queue size. Please delete one or more files from your upload. You can clear your queue by clicking the button below.');
jQuery('#attachment').uploadify('cancel', '*');
}
},
onUploadSuccess: function (file, data, response) {
jQuery('.submit').removeAttr('disabled');

try {
obj = jQuery.parseJSON(data);
if (obj.success) {
jQuery('#' + file.id).append('<input type="hidden" name="temp_image_path[]" value="' + obj.file.name + '" /><input type="hidden" name="original_name[]" value="' + obj.file.original_name + '" />');
}
} catch (e) {
// do nothing
}


},
onUploadError: function (file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
onQueueComplete: function () {
jQuery('.submit').removeAttr('disabled');
},
onClearQueue: function (queueItemCount) {
//jQuery('.submit').attr('disabled', 'disabled');
var file = (queueItemCount == 1) ? 'file has' : 'files have';
alert(queueItemCount + ' ' + file + ' been removed from your upload queue. You have no files pending upload.');
$.cookie('size', 0);
jQuery('#attachment').uploadify('settings', 'uploadLimit', 5);
},
formData: {
'filetypes': '*.jpg; *.gif; *.png; *.jpeg; *.doc; *.docx; *.zip; *.pdf; *.xls; *.xlsx; *.JPG',
'folder': 'temp',
'time': UPLOAD_TIME,
'token': UPLOAD_TOKEN
}
});

最佳答案

我也未能找到开箱即用的解决方案。取消方法仅影响尚未上传的文件。

我建议您可以使用自定义处理程序来删除上传的文件(或所有文件)。靠近 unlink 调用的地方。并且您不能将 uploadLimit 重置为 5,而是通过删除的文件数增加 uploadLimit

但是 uploadify 对象仍然具有有关上传文件的信息 - 这意味着如果用户尝试加载相同的文件,他将收到有关重复文件的警告消息。您可以清除此集合:

var files = $('#attachment').data('uploadify').queueData.files = [];
for (var member in files) delete files[member];

从您的代码中使用它可能不正确,但您可以扩展该插件。

关于jquery - Uploadify:如何从队列中删除已上传的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18262311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com