2011-05-30 25 views
1

我已經下載了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', function(event, file, errorCode, message) 
    { 
     alert('Size of the file '+file.name+' is greater than limit'); 
    }) 
    .bind('uploadStart', function(event, file) 
    { 
     $('#log li#'+file.id).find('span.progressvalue').text('0%'); 
    }) 
    .bind('uploadProgress', function(event, file, 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', function(event, file, serverData) 
    { 
     var item = $('#log li#'+file.id); 
     item.find('div.progress').css('width', '100%'); 
     item.find('span.progressvalue').text('100%'); 
    }) 
    .bind('uploadComplete', function(event, file) 
    { 
     // upload has completed, try the next one in the queue 
     $(this).swfupload('startUpload'); 
    }) 

}); 

回答

3

如果你正在處理上傳隊列,這是很簡單的使用swfupload.queue plugin

然後,你可以綁定swfupload對象上的'queueComplete'事件,在整個隊列處理完畢後(這是您希望隱藏進度條並重置隊列的位置)將觸發該事件。爲了重置隊列,這個插件還添加了一個cancelQueue()函數(請注意你在哪裏調用它,因爲它會取消任何正在進行的上傳)。

如果你想手工取消/不使用這個插件,你必須通過一個直到統計(取消文件之一)對象說,這是空

// 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(); 
} 
1

我想你的意思是「如何上傳後重置統計信息?「。

在某些時候,例如您將file_upload_limit設置爲1,則您上傳文件但在此之後將其刪除,您需要重置統計信息,否則無法繼續上傳任何文件。現在

,您可以編寫代碼如下:

var stats = swfUploadObj.getStats(); 
    stats.successful_uploads = stats.successful_uploads - 1; 
    swfUploadObj.setStats(stats);