I'm working on a file uploader where I want my users to be able to upload multiple files at the same time, and multiple files one by one. I saw a lot of other pages with similar questions, but none of them could solve my problem.
This is my html upload Form:
<form id="myform" action="upload.php" method="post" enctype="multipart/form-data" >
<h3>Upload File</h3>
<input type="file" name="myfile[]" id="uploadFile" multiple>
<button type="submit" id="mySubmitButton" onclick="saveData()" name="save">UPLOAD</button>
</form>
I think FormData is the right approach for my case, but I'm not sure. I want to make an array of the files and send them through a PHP file, where they are sent to a server. I really don't want to use ajax.
This is my Javascript code:
<script>
function saveData(){
formData.getAll("myfile[]");
}
$('#uploadFile').on('change', function() {
var formData = new FormData();
var files = $('#uploadFile')[0].files;
for (var i = 0; i < files.length; i++) {
formData.append('myfile[]', document.getElementById('uploadFile').files[i]);
}
});
</script>
This isn't working. Now I only upload the last selected file. Hope you can help me, thanks in advance!
"multiple files one by one"does that mean sequentially (pick all and upload 1,2,3... ) or individually(pick file -> upload, pick another -> upload etc )?FormDatause does not - how are you going to use that if you do not use Ajax?