I have an html input of type file. the files that the user uploads are sent to a php code via an ajax. My html code:
<input type="file" id="attachments" name="attachments[]" multiple>
My ajax function:
var formData = new FormData(document.querySelector("form"));
$.ajax({url: "target.php",
type:"POST" ,
data:formData,
processData: false,
contentType: false ,
success: function(result){
//do somthing
}
});
My php code:
foreach(array_keys($attachments['name']) as $key) {
$file_name = $attachments['name'][$key];
$file_location = $attachments['tmp_name'][$key];
echo $file_name.$file_location;
}
The problem is that on the php side, when the user uploads an image, the code works just fine, but when i upload a .mp3 file the $file_location
variable is empty even though the $file_name
is correct. Anyone knows why this happens ?