First of all, i search in many many topics about that and i dont want to use any plugins.
function addToDatabase(menuItem){
var formData = new FormData();
formData.append("Description", document.getElementById("DescriptionID").value);
jQuery.each($('#filesID')[0].files, function(i, file) {
formData.append('file-'+i, file);
});
$.ajax({
type: "POST",
url: "dbAdder.php",
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(result){
$("#PageContent").html(result);
}
});
}
Js function that sending to server things. While in the server-side code $_POST['Description']
have value, but $_FILES['file-0']
doesnt.
<input type="file" id="filesID" name="files[]" multiple />
<textarea id="DescriptionID" rows="5" cols="53"></textarea>
HTML part of code.