HTML5 file uploading with multiple progress bars

前端 未结 2 1808
孤城傲影
孤城傲影 2020-12-25 08:49

I\'m uploading multiple files via XmlHTTPRequest and HTML5. I have the uploading working fine, but I would like to have a progress bar for each file upload going on. The c

2条回答
  •  梦谈多话
    2020-12-25 09:10

    I think I found a solution for this problem. It looks working on some of my tests. I'm not very good at english thus I'll just share my sample script. If you ask any question, I'll try to explain more :)

    // This is input object which type of file.  
    var uploader = document.getElementById("fileUploader"); 
    
    // We'll send a new post for each file.
    for(var i=0, j=uploader.files.length; i
    '); }); xhr.addEventListener("progress", function(e){ var total = e.total; var loaded = e.loaded; var percent = (100 / total) * loaded; // Calculate percentage of loaded data // I animate progress object. Notice that i use "this.progressId" which i created on loadstart event. $("#" + this.progressId).animate({"width":300 * (percent / 100)}, 800); }); xhr.open("POST","index.php"); xhr.send(uploaderForm); }

提交回复
热议问题