File upload

This commit is contained in:
2021-10-23 18:47:10 +03:00
parent 0c6f9f0aa3
commit 2edb4e445f
5 changed files with 38 additions and 57 deletions

10
main.js
View File

@@ -4,7 +4,7 @@ $(document).on('click', 'div.dropdown-menu', function (e) {
const buttons = document.querySelectorAll('.delete-button')
buttons.forEach((button) => {
button.addEventListener("click", async function(event) {
button.addEventListener("click", async function (event) {
const response = await fetch("delete.php", {
method: 'POST',
headers: {
@@ -14,4 +14,12 @@ buttons.forEach((button) => {
body: `file=${event.target.dataset.file}`
});
})
});
const fileInput = document.getElementById('upload');
fileInput.addEventListener('change', async function (event) {
const file = event.target.files[0];
let formData = new FormData();
formData.append("file", file);
fetch('upload.php', { method: "POST", body: formData });
});