I am using simple ajax call to submit form data where I am trying to POST some form inputs along with an file.
$("#submit-uploaded-audio").on("click", function () {
var post_data = new FormData();
var file = $("#audio_file").prop('files')[0];
post_data.append('key1', 'value1');
post_data.append('key2', 'value2');
post_data.append('file', file);
$.ajax({
url: "/process_audio_upload",
type: "POST",
data: post_data,
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
// some logic
},
error: function(error) {
// some logic here
}
});
});
Ajax call goes to the server url (codeigniter framework) but data posted in call is not getting populated into $_POST as well as $_FILES (both arrays are empty)
Checked php.ini settings and file upload settings looks good
However, "php://input" shows required data in raw format
var_dump(file_get_contents("php://input"));
I want to get this data into respective $_POST and $_FILES array so that I can do further actions.
Thanks in advance.
Also tried following solutions