这是我的代码如下:
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',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,{name: 'image_description',index: 'image_description',maxlength: "50"}} } ];
我正在使用ajaxFileUpload,这是我上传相同的代码:
afterSubmit: function (response) { if(response.responseJSON){ $.ajaxFileUpload({ url: fileuploadUrl,secureuri:false,fileElementId:'image',dataType: 'json',success: function (data,status) { alert("Upload Complete."); } }); } return [true]; } },
这个fileElementId指的是图像.图像只被挑选一次.尝试将图像分配给图像[],就像我们从纯HTML一样.但仍然没有运气,因为ajaxFileUpload.js抛出错误,因为图像[]找不到id.
解决方法
您可以尝试滚动自己,像(未测试):
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]; } ...
然后你可以使用$_FILES [‘files’]访问PHP上传脚本中的文件
否则你可以使用像jQuery File Upload这样的插件