使用 uploadifive 进行多文件上传会导致重复调用 check_exists [英] Using uploadifive for multiple file upload causes repeated invocations of check_exists

查看:44
本文介绍了使用 uploadifive 进行多文件上传会导致重复调用 check_exists的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用uploadifive(HTML5版本不是基于Flash的uploadify)如下:

Am using uploadifive (the HTML5 version not the the Flash based uploadify) as follows:

$('#file_upload').uploadifive({ //setup uploadify
    'auto'             : false,
    'removeCompleted'  : true,
    'checkScript'    : 'check-exists.php',
    'formData'         : {
                              'timestamp' : '<?php echo $timestamp;?>',
                              'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                         },
    'queueID'          : 'queue',
    'uploader'         : 'uploadifive.php',
    'onUploadFile'     : function(file) {
                            //alert('The file ' + file.name + ' is being uploaded.');
                         },
    'onCheck'          : function(file, exists) {
                           //alert ('onCheck: ' + file.name + '/' + exists);
                         },
    'onUploadComplete'  : function(file, data) { 
                          //alert (file.name + ': ' + data); 
                         }
});

用这个简单的形式:

<form>
    <div id="queue"></div>
    <input id="file_upload" name="file_upload" type="file">
    <a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>
</form>

如果我将一两个文件加载到一个空文件夹中,则一切正常.
如果我加载 3 个或更多,我会收到不同数量的对 check_info.php 的重复调用.例如,如果我将五个文件上传到一个空文件夹中,根据萤火虫,有 15 次调用 check_info.
1 表示文件 1,返回 0(即文件不存在)
2 对于文件 2,都返回 0
3 对于文件 3,都返回 0
4 表示文件 4,1 返回 0,3 返回 1(即文件存在)
5 表示文件 5,2 返回 0,3 返回 1
我可以接受 0 的多次返回(尽管它非常低效),因为它们对用户不可见,但是 1 的 6 次返回,每个都会生成用户必须响应的警告消息.
我不知道为什么会发生这种情况.看过上传代码,但它超出了我对 jQuery 的有限了解.
感谢任何建议/建议/治疗/等
提前发送

If I load one or two files into an empty folder, all works fine.
If I load 3 or more I get a variable number of repeated calls to check_info.php. For instance if I upload five files into an empty folder, according to firebug there are 15 calls to check_info.
1 for file 1, returns 0 (ie file does not exist)
2 for file 2, both return 0
3 for file 3, all return 0
4 for file 4, 1 returns 0 and 3 return 1 (ie file exists)
5 for file 5, 2 return 0, 3 return 1
The multiple returns of 0 I can live with (though it's very inefficient) as they are invisible to the user, but the 6 returns of 1, each generate a warning msg to which the user has to respond.
I have no idea why this happening. Have looked at uploadifive code but it's way beyond my limited knowledge of jQuery.
Appreciate any advice/suggestions/cures/etc
Tx in advance

推荐答案

我在测试过程中也遇到了这个问题.我通过修改源代码解决了这个问题……您必须寻找注释//Loop through the files"才能找到它的去向.基本上,我只是运行两个循环......一个用于检查,另一个用于上传以避免冲突.

I ran into this during my testing as well. I fixed this by modifying the source code... you'll have to hunt for the comment "// Loop through the files" to find where it goes. Basically, I simply run two loops... one for the check, and the other for the upload to avoid conflicts.

// Loop through the files to run check scripts first...
if (settings.checkScript) {
    $('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').each(function () {
        _file = $(this).data('file');
        if (typeof _file.skipFile === 'undefined') {
            _file.skipFile = $data.checkExists(_file);
        }
    });
}
// Loop through the files for uploading...
$('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').each(function() {
    _file = $(this).data('file');
    // Check if the simUpload limit was reached
    if (($data.uploads.current >= settings.simUploadLimit && settings.simUploadLimit !== 0) || ($data.uploads.current >= settings.uploadLimit && settings.uploadLimit !== 0) || ($data.uploads.count >= settings.uploadLimit && settings.uploadLimit !== 0)) {
        return false;
    }
    if (!_file.skipFile) {
        $data.uploadFile(_file, true);
    }
});

当然希望我有办法让作者得到我的其他修复,但他的论坛已关闭,他无法联系他.我只想说,这不是我遇到的唯一问题.

Sure wish I had a way to get my other fixes to the author, but his forum is shutdown and he leaves no way to contact him. Suffice it to say, this wasn't the only problem I had.

这篇关于使用 uploadifive 进行多文件上传会导致重复调用 check_exists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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