For multiple files in ajax try this
var url = "your_url";
var data = $('#form').serialize();
var form_data = new FormData();
//get the length of file inputs
var length = $('input[type="file"]').length;
for(var i = 0;i<length;i++){
file_data = $('input[type="file"]')[i].files;
form_data.append("file_"+i, file_data[0]);
}
// for other data
form_data.append("data",data);
$.ajax({
url: url,
type: "POST",
data: form_data,
cache: false,
contentType: false, //important
processData: false, //important
success: function (data) {
//do something
}
})
In php
parse_str($_POST['data'], $_POST);
for($i=0;$i<count($_FILES);$i++){
if(isset($_FILES['file_'.$i])){
$file = $_FILES['file_'.$i];
$file_name = $file['name'];
$file_type = $file ['type'];
$file_size = $file ['size'];
$file_path = $file ['tmp_name'];
}
}