How to pass formData array to php load file. How to pass all file input as array or iterate it ?
$(document).ready(function(){
$('.add_more').click(function(e){
e.preventDefault();
$(this).before("<input name='file[]' class='file' type='file' /> <br> <input type='button' class='es' name='es' value='Upload This File' />");
});
$('.es').click(function (e) {
e.preventDefault();
var form = $('.form');
var formData = new FormData(form);
// | |
formData.append('file', $('.file')[0].files[0]);
$.ajax({
url: 'lib/upload.php',
type: 'post',
data: formData,
contentType: false,
processData: false,
cache: false,
success: function (data) {
$('#here').html(data);
}
});
});
});
And html (php) file :
<form id="form" action="" enctype="multipart/form-data" method="post">
<input name="file[]" class="file" type="file" />
<input type="button" name="es" class="es" value="Upload This File" />
<br><br>
<button class="add_more">Add More Files</button>
</form>
How to pass all file input as array?