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;
});
});
input[name^="uploadFile"]in a<form>when you the user drops. Then we can have a generic submit function. When they click it, we prevent the default functionality. Iterate over all the form elements, take the data we need, then use$('form').submit()to perform the normal functionality.