Added a progress bar

This commit is contained in:
2022-01-04 12:34:53 +03:00
parent 6011a350f7
commit 632ba780af
2 changed files with 23 additions and 5 deletions

21
main.js
View File

@@ -17,12 +17,25 @@ buttons.forEach((button) => {
});
const fileInput = document.getElementById('upload');
const progressBar = document.getElementById('progress');
fileInput.addEventListener('change', async function (event) {
const file = event.target.files[0];
let formData = new FormData();
formData.append("file", file);
const response = await fetch('upload.php', { method: "POST", body: formData });
if (response.status === 200) {
// const response = await fetch('upload.php', { method: "POST", body: formData });
// if (response.status === 200) {
// window.location.reload(false);
// }
axios.request({
method: "post",
url: "upload.php",
data: formData,
headers: { "Content-Type": "multipart/form-data" },
onUploadProgress: (p) => {
progressBar.style.display = 'block';
progressBar.style.width = `${p.loaded / p.total}%`;
}
}).then (data => {
window.location.reload(false);
}
});
})
});