PLUpload获取剩余文件? [英] PLUpload Get Files Remaining?

查看:124
本文介绍了PLUpload获取剩余文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用PLUpload来上传文件。但是,我遇到了一个问题。我正在尝试在队列完成时触发事件。我很亲密,但并不完全。见这里:

So I'm using PLUpload to, well, upload files. However, I've run into a problem. I'm trying to fire an event when the queue is completed. I'm close, but not quite there. See here:

$(function() {
    var files_remaining = 0;

    // Setup flash version
    $("#flash_uploader").pluploadQueue({
        // General settings
        runtimes : 'flash',
        url : 'blah.php',
        max_file_size : '200mb',
        chunk_size : '1mb',

        // Flash settings
        flash_swf_url : 'plupload.flash.swf'
    });

    var uploader = $("#flash_uploader").pluploadQueue();

    uploader.bind('FilesAdded', function(up, file, res)
    {
        files_remaining++;
    });

    uploader.bind('FileUploaded', function(up, file, res)
    {
        files_remaining--;
        if (files_remaining == 0)
        {
            alert('Complete!');
        }
    });
});

注意最后两个 .bind()使用。基本上,我正在尝试更新变量以确定已上载了多少文件,然后在队列完成时找出(基于此)。但是,您可能知道,FilesAdded不是基于每个文件运行,而是在将任意数量的文件添加到队列时运行。如果添加了三个文件,则只会调用一次FilesAdded。这意味着只有在一次上传一个文件时,此尝试才有效。

Notice the last two .bind() uses. Basically, I'm trying to update a variable to figure out how many files have been uploaded, and then figure out (based on that) when the queue has been completed. However, as you likely know, FilesAdded isn't run on a per-file basis, but is instead run when any amount of files are added to the queue. If three files are added, FilesAdded is only called once. That means this attempt only works if one file is uploaded at a time.

所以,我的问题是:获得剩余文件数量的最佳方法是什么队列,或最终(甚至更好)每次队列完成时调用一个事件?我知道很多人都有这个问题,但我还没有找到一个解决方案,我已经能够开始工作了!

So, my question is this: what is the best way to get the number of files remaining in the queue, or ultimately (even better) call an event everytime the queue finishes? I know lots of people have this problem, but I haven't found a single solution I've been able to get work!

谢谢!

推荐答案

$(function() {
    var files_remaining = 0;

    // Setup flash version
    $("#flash_uploader").pluploadQueue({
        // General settings
        runtimes : 'flash',
        url : 'blah.php',
        max_file_size : '200mb',
        chunk_size : '1mb',

        // Flash settings
        flash_swf_url : 'plupload.flash.swf'
    });

    var uploader = $("#flash_uploader").pluploadQueue();

    uploader.bind('QueueChanged', function(up, files)
    {
        files_remaining = uploader.files.length;
    });

    uploader.bind('FileUploaded', function(up, file, res)
    {
        files_remaining--;
        if (files_remaining == 0)
        {
            alert('Complete!');
        }
    });
});

这篇关于PLUpload获取剩余文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆