Using uploadifive for multiple file upload causes repeated invocations of check_exists

1.9k views Asked by At

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); 
                         }
});

With this simple form:

<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>

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

1

There are 1 answers

1
Andrew Koransky On

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.