我已经下载了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');
    })

});

最佳答案

如果您要处理上传队列,则使用swfupload.queue plugin更为简单

然后,您可以在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();
}

10-03 01:14