Here is my code below:
let colNames = ['ID', 'Image', 'Title', 'Description'];
let colModel = [
{name: 'id', index: 'id', width: 30, editable: true, editoptions: {size: "30", maxlength: "50"}},
{
name: 'image',
index: 'image',
align: 'left',
editable: true,
edittype: 'file',
editoptions: {
multiple: true,
accept: ".jpg,.png,.jpeg",
enctype: "multipart/form-data"
},
width: 210,
align: 'center',
formatter: imageFormatter,
search: false
},
{name: 'image_title', index: 'image_title', width: 150, editable: true, editoptions: {size: "30", maxlength: "50"}},
{name: 'image_description', index: 'image_description', width: 150, editable: true, editoptions: {size: "30", maxlength: "50"}}
}
];
I am using ajaxFileUpload and here is my code to upload the same:
afterSubmit: function (response) {
if(response.responseJSON){
$.ajaxFileUpload({
url: fileuploadUrl,
secureuri:false,
fileElementId:'image',
dataType: 'json',
success: function (data, status) {
alert("Upload Complete.");
}
});
}
return [true];
}
},
This fileElementId
is referring to image
. Where image
is picked only once. Tried assigning image to images[]
as we do it from plain HTML. But still no luck as ajaxFileUpload.js throwing error as id not found with images[]
.
You could try rolling your own, something like (not tested):
afterSubmit: function (response) {
if(response.responseJSON){
var form_data = new FormData();
var count = document.getElementById('image').files.length; // assuming your file input names is image
for (var x = 0; x < count; x++) {
form_data.append("files[]", document.getElementById('image').files[x]);
}
$.ajax({
url: 'upload_files.php', // your php upload script
dataType: 'text', // what to expect back from the php upload script
cache: false,
contentType: false,
processData: false,
data: form_data, // data created above
type: 'post',
success: function (response) {
alert("Upload Complete.");
},
error: function (response) {
// handle any errors
}
});
}
return [true];
}
...
Then you could access the files in your php upload script with $_FILES['files']
Otherwise you could use a plugin like jQuery File Upload
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With