如何从jqgrid和Laravel上传多个文件?

Mit*_*tsa 7 javascript ajax jquery jqgrid laravel

这是我的代码如下:

  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"}}
        }
    ];
Run Code Online (Sandbox Code Playgroud)

我正在使用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];
                }
            },
Run Code Online (Sandbox Code Playgroud)

fileElementId是指image.哪里image只挑选一次.尝试images[]从纯HTML中分配图像.但仍然没有运气,因为ajaxFileUpload.js抛出错误,因为找不到id images[].

Mit*_*tsa 0

afterSubmit: function (response) {
    if(response.responseJSON){
        // Simple change here
        $('#image').attr('name', 'images[]');
        $.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: {
                rowId: rowId,
                _token: $('meta[name="csrf-token"]').attr('content')                                
            },
            fileElementId:'image',
            type: 'post',
            success: function (response) {
                alert("Upload Complete.");
            },
            error: function (response) {
                // handle any errors
            }
        });
    }          
    return [true];
}
Run Code Online (Sandbox Code Playgroud)

由于jqgrid动态创建id和name,对于多个文件上传,我们需要name数组。因此,动态更改为名称数组,该数组在内部处理后端的所有内容。