简体   繁体   中英

How to upload 1 file at a time with multiple selection using blueimp jquery-file-upload?

I'm using blueimp's jquery-file-upload to upload mulitple photos

https://blueimp.github.io/jQuery-File-Upload/

I've created a multiple selection input box and setup the upload script:

<script>
$(function () {
    $("#upload_files").fileupload({
        autoUpload: true,
        dataType: "json",
        singleFileUploads: true,
        sequentialUploads: false,
        url: "/photos/my_upload_script",
        add: function (e, data) {

            data.submit();

        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $("#version_progress_bar .progress-bar").css("width",progress + "%");
        },
        done: function (e, data) {
            if(data.result.status == "success"){
                alert('well done');
            }
            else {
                alert("it's gone pete tong!");
            }
        }
    });
});
</script>

The problem I have, is my historic naming convention for uploaded photos. I'm restricted in that I must use PHP's time() function. This becomes a problem when more than one photo's upload is triggered within the same second.

So, is there a way I can get jquery-file-upload to upload each photo one-by-one but still allow multiple selections in hopes that this will prevent photos uploading within the same second?

I couldn't find a way to do it within the script. So, instead, I put a 1 second sleep on my ajax script.

is there a way I can get jquery-file-upload to upload each photo one-by-one but still allow multiple selections

Yes. You already have the option in your code that decides this behavior:

sequentialUploads: false,

Change that to true and you upload sequentially, one after another..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM