Currently, I am utilizing ajax for uploading files. Once the file has been uploaded, PHP needs to conduct a thorough check on it (including mime type, size, virus scan using clamscan, and more). This process can take a few seconds, especially for larger files. While the file is being uploaded, an HTML5 <progress>
bar fills up. However, once PHP begins its verification process, the progress should switch to "indeterminate." I have explored two possible solutions to achieve this transition, but unfortunately, both have not yielded the desired results:
Solution 1: Monitoring upload.onload event
xhr.upload.addEventListener("load", function (e) {
$("#uploadprogress").attr("value", false);
$("#uploadprogress").attr("max", false);
$("#progress").text("Checking file...");
});
This approach proved ineffective as the onload
event triggers when the request is ready, rather than when the upload process is complete.
Solution 2: Verifying if upload progress percentage equals 100%
xhr.upload.addEventListener("progress", function (e) {
if (e.lengthComputable && e) {
p = (e.loaded / e.total);
if (p == 1) {
$("#uploadprogress").attr("value", false);
$("#uploadprogress").attr("max", false);
$("#progress").text("Checking file...");
} else {
var percent = Math.ceil(p * 1000) / 10;
$("#uploadprogress").val(e.loaded);
$("#uploadprogress").attr("max", e.total);
$("#progress").text("Uploading... " + percent + "%");
}
}
}
});
Unfortunately, the second solution also fell short because there were instances where the upload progress would halt around 97%, even though the file was fully uploaded and PHP had commenced handling it.
Could you suggest any alternative approaches for addressing this issue?