Add file upload

This commit is contained in:
2024-04-25 10:19:24 +02:00
parent eb3086cb12
commit 2f49e6aa8a
5 changed files with 34 additions and 22 deletions

View File

@@ -537,4 +537,24 @@ if ("loading" === document.readyState) {
document.addEventListener("DOMContentLoaded", initAjax);
} else {
setTimeout(initAjax, 0);
}
function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
let formData = new FormData();
formData.append('userfile', file);
let xhr = new XMLHttpRequest();
xhr.open('POST', '__URL__', true);
xhr.onload = function () {
if (xhr.status === 200) {
document.getElementById('uploadStatus').innerHTML = 'File uploaded successfully.';
} else {
document.getElementById('uploadStatus').innerHTML = 'Error uploading file.';
}
};
xhr.send(formData);
}