은 내가이 문제에 대한 해결책을 찾은 것 같아요. 그것은 내 테스트 중 일부에서 작동하는 것 같습니다. 영어에 능숙하지 않아 샘플 스크립트를 공유 할 것입니다. 어떤 질문을하면 더 설명하려고합니다 :)
// 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<j; i++)
{
var uploaderForm = new FormData(); // Create new FormData
uploaderForm.append("action","upload"); // append extra parameters if you wish.
uploaderForm.append("up_file",uploader.files[i]); // append the next file for upload
var xhr = new XMLHttpRequest();
xhr.addEventListener("loadstart", function(e){
// generate unique id for progress bars. This is important because we'll use it on progress event for modifications
this.progressId = "progress_" + Math.floor((Math.random() * 100000));
// append progress elements to somewhere you want
$("body").append('<div id="' + this.progressId + '" class="myCustomProgressBar" ></div>');
});
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);
}
정말 고마워! 원래 모든 파일을 배열의 큐에 추가하려고 시도했지만 작동하지 않습니다. D 파일을 만들 때 다음과 같이 도움을주었습니다. http://userscripts.org/scripts/show/158420 – Pluto
이 예제에서 보듯이 각 파일에 대해 별도의 진행률 표시 줄을 사용하려는 경우, 하나의 XHR에 모든 파일이 추가 된 대신 각 파일에 대해 별도의 XHR을 가져야합니다. 진행 이벤트에 이벤트가 어떤 파일에 통계를 제공했는지 나타내는 메타 데이터가 있어야합니다. –
나를 위해 작동하지 않습니다 xhr.addEventListener ("progress", function (e) {}), xhr.upload.onprogress = function (e) {}을 사용해야했습니다. – maylon