I know there has been several questions regarding this very question and I have combed through many of them and have not found a right way to accomplish the goal properly. Essentially, I am trying to capture multiple file inputs in the form and push them to PHP. I have the PHP part at least figured out but its the Jquery im struggling with. One of the main problems I have noticed through debugging is that my action parameter is not getting through at all. My code I posted is below. Any help would be greatly appreciated. Thanks.
$(document).ready(function () {
//if submitting imgages form
$('#submit').click(function () {
// match anything not a [ or ]
regexp = /^[^[\]]+/;
var fileInput = $('.putImages input[type="file"]');
var fileInputName = regexp.exec(fileInput.attr('name'));
// make files available
var data2 = new FormData(fileInput);
jQuery.each($(fileInput)[0].files, function (i, file) {
data2.append(fileInputName + '[' + i + ']', file);
});
//organize data
var data = new FormData($('input[name^="uploadFile"]'));
jQuery.each($('input[name^="uploadFile"]')[0].files, function (i, file) {
data.append(i, file);
});
$.ajax({
type: 'GET',
url: 'productadminupdate.php',
data: data2 + "&action=" + 'images',
cache: false,
contentType: false,
processData: false,
success: function (response) {
$('#imgform_result').html(response).fadeIn();
}
});
return false;
});
});
I don’t know if I got it, but when people think about ajax uploader, they don’t really know that. In reality, it is not JavaScript doing the job.
The technique exists in targeting the action of the form to an Iframe.
This Iframe should be hidden
Here is an example:
So in the Iframe, your php code will make the upload, getting the information using $_FILES.