如何在SWFUpload中重置队列?

问题描述

| 我已经下载了SWFUpload,希望创建可以在我的网站上上传文件功能。 我找到了该指南:http://webdeveloperplus.com/jquery/multiple-file-upload-with-progress-bar-using-jquery/,我认为我可以从这里开始。不同之处在于,我一次只允许上传一张图片。但是我不知道上传文件后如何还原SWFUpload吗?我希望重置队列,并消失进度条。 调试说:
SWF DEBUG: Event: uploadError : Upload limit reached. No more files can be uploaded.
这是我的SWFUpload代码
$(function()
{
    $(\'#swfupload-control\').swfupload({
          upload_url                : \"upload-file.PHP\",file_post_name            : \'uploadfile\',file_size_limit           : \"102400\" // 100 MB,file_types                : \"*.jpg;*.png;*.gif\",file_types_description    : \"Image files\",file_upload_limit         : 1,flash_url                 : \"js/swfupload/swfupload.swf\",button_image_url          : \'js/swfupload/wdp_buttons_upload_114x29.png\',button_width              : 114,button_height             : 29,button_placeholder        : $(\'#button\')[0],debug                     : true
    })
    .bind(\'fileQueued\',function(event,file)
    {
        var listitem=\'<li id=\"\'+file.id+\'\">\'+
            \'<span class=\"progresstext\"><span class=\"progressvalue\"></span> \'+file.name+\'</span>\'+
            \'<div class=\"progressbar\"><div class=\"progress\"></div></div>\'+
            \'</li>\';
        $(\'#log\').append(listitem);
        // start the upload since it\'s queued
        $(this).swfupload(\'startUpload\');
    })
    .bind(\'fileQueueError\',file,errorCode,message)
    {
        alert(\'Size of the file \'+file.name+\' is greater than limit\');
    })
    .bind(\'uploadStart\',file)
    {
        $(\'#log li#\'+file.id).find(\'span.progressvalue\').text(\'0%\');
    })
    .bind(\'uploadProgress\',bytesLoaded)
    {
        //Show Progress
        var percentage = Math.round((bytesLoaded/file.size)*100);
        $(\'#log li#\'+file.id).find(\'div.progress\').css(\'width\',percentage+\'%\');
        $(\'#log li#\'+file.id).find(\'span.progressvalue\').text(percentage+\'%\');
    })
    .bind(\'uploadSuccess\',serverData)
    {
        var item = $(\'#log li#\'+file.id);
        item.find(\'div.progress\').css(\'width\',\'100%\');
        item.find(\'span.progressvalue\').text(\'100%\');
    })
    .bind(\'uploadComplete\',file)
    {
        // upload has completed,try the next one in the queue
        $(this).swfupload(\'startUpload\');
    })

});
    

解决方法

        如果要处理上传队列,则使用swfupload.queue插件要简单得多。 然后,您可以在swfupload对象上绑定\'queueComplete \'事件,该事件将在处理完整个队列后触发(这是您要隐藏进度条并重置队列的位置)。要重置队列,此插件还添加了cancelQueue()函数(不过请注意调用位置,因为它将取消所有正在进行的上载)。 如果要手动取消/不使用此插件,则必须逐个取消文件,直到stats()对象说它为空。
// request your stat objects,it contains amongst others the number of files in the queue
var stats = my_upload.getStats();
// while the queue is not empty ...
while (stats.files_queued > 0) {
  // .. cancel the first in the queue (null: take the first found,false: don\'t trigger an error event)
  my_upload.cancelUpload(null,false);
  // it is important to reload the stats everytime and not just do a for (i = 0; i < stats.files_queued ...
  stats = my_upload.getStats();
}
    ,        我认为您的意思是“上传后如何重置统计信息?”。 在某些时候(例如将ѭ3设置为1),您上传了文件,但之后将其删除,则需要重置统计信息,否则将无法继续上传任何文件。 现在,您可以编写如下代码:
  var stats = swfUploadObj.getStats();
  stats.successful_uploads = stats.successful_uploads - 1;
  swfUploadObj.setStats(stats);