Blueimp / Jquery file upload progress bar for each file
Asked Answered
S

1

7

How do I create a progress bar for each file with jQuery File Upload(Blueimp http://goo.gl/y1Y2b)? I have multiple forms and each form has an upload button.

$('.fileupload').fileupload({
dataType: 'json',
add: function (e, data) {
    var formContainer = $($(this).parent()).parent();
    var file = data.files[0];
    var li  = $('<li/>').attr("id", 'li-upload-'+file.id).appendTo($(formContainer).children('.ul-files'));
    var link= $('<a/>').attr("href", '#').attr("data-href", file.delete_url).addClass("link-remove-file pull-right").attr("target", "_parent").attr("title", "Remove").appendTo(li);
    var ico = $('<i/>').addClass('icon-remove').appendTo(link);
    var spn = $('<span/>').html(file.name+' ('+Math.round(file.size/1024)+' K)').appendTo(li);
    var lod = $('<div/>').addClass('container-progress-upload').css("float", 'right').appendTo(li);
    var prg = $('<div/>').addClass('bar').css("width", '0%').attr("id", 'pgr-'+file.name).appendTo(lod);
    data.submit();
},
progress: function (e, data) {
    var file = data.files[0];
    var progress = parseInt(data.loaded / data.total * 100, 10);

    $('#pgr-'+file.name).css(
        'width',
        50 + '%'
    );
}
});
Selfcontrol answered 27/12, 2012 at 17:41 Comment(2)
I am stuck at the same point.Did you get across this?Can you add the answer?Auspice
I do this: HTML <input class="fileupload" type="file" name="files[]" data-url="<?php echo site_url('ticket/postFile');?>" multiple> JS: $(window).load(function () { 'use strict'; $('.form-upload').fileupload({ dataType: 'json', autoUpload: true, url: $('.form-upload').attr('data-url-upload'), maxFileSize: 5000000 });Selfcontrol
S
2

Well, solved, i just do this:

I do this: HTML

<form id="frm-resposta-{CODHIST}" class="form-horizontal form-upload" method="post" action="<?php echo site_url('ticket/salvarhistorico');?>" enctype="multipart/form-data" data-url-upload="<?php echo site_url('ticket/postFile');?>">
<input class="fileupload" type="file" name="files[]" data-url="<?php echo site_url('ticket/postFile');?>" multiple>

JS:

$(window).load(function () {
    'use strict';
$('.form-upload').fileupload({
        dataType: 'json',
        autoUpload: true,
        url: $('.form-upload').attr('data-url-upload'),
        maxFileSize: 5000000
    });
Selfcontrol answered 26/2, 2013 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.