I have a problem here in saving images from an array. Well I have a multiple array using AJAX POST to PHP(codeigniter). What I want to do is to save multiple row of images from html table to my desired folder path. Do you know how to achieve this or a way?
This is the code in saving
$('#save').click(function(){
var image_data = [];
$('#list tbody tr').each(function (row, tr){
if ($(tr).find('td:eq(0) img').data('file_name') != '') {
image_len[row] = {
'image_len' : $(tr).find('td:eq(0) img').data('file_name')
}
}
});
console.log(image_data);
console.log(my_other_data1);
console.log(my_other_data2);
})
This is the result in image_data
(2) [{…}, {…}]
0: {image_len: "C:\fakepath\asd.png"}
1: {image_len: "C:\fakepath\123.png"}
This is my AJAX
var data = {
my_other_data1: my_other_data1,
my_other_data2: my_other_data2,
image_data: image_data
};
$.ajax({
data: data,
type: "POST",
url: "<?php echo base_url('My_Controller/save'); ?>",
dataType: 'json',
crossOrigin: false,
beforeSend: function() {
},
success: function(result) {
},
failure: function(msg) {
console.log("Failure to connect to server!");
},
error: function(status) {},
xhr: function() {
var xhr = $.ajaxSettings.xhr();
xhr.onprogress = function(evt) {
$("body").css("cursor", "wait");
};
xhr.onloadend = function(evt) {
$("body").css("cursor", "default");
};
return xhr;
}
});