我在Codeigniter中使用this plugin,因为我想上传多个文件(可以是多个图片,视频或文件),如上所述,我已经完成了以下代码
<div class="form-group">
<label for="attachments"></label>
<input id="attachment" name="attachment[]" type="file" class="file" multiple>
</div>
$("#attachment").fileinput({
uploadUrl: '#',
uploadAsync: false,
showCaption: false,
fileActionSettings: {
showRemove: true,
showUpload: false,
showZoom: true,
showDrag: false
},
showUpload:false,
allowedFileExtensions: ["jpg", "jpeg", "gif", "png", "mp4", "txt", "docx", "pptx", "xlsx", "pdf", "ppt", "xls", "doc"],
overwriteInitial: false,
initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup
initialPreviewFileType: 'image', // image is the default and can be overridden in config below
purifyHtml: true // this by default purifies HTML data for preview
}).on('filesorted', function (e, params) {
console.log('File sorted params', params);
}).on('fileuploaded', function (e, params) {
console.log('File uploaded params', params);
});
但上述代码无法正常工作,因为我只获取最后选择的图像而不是获取所有选定的图像。
这是我在$_FILES[]
Array
(
[attachment] => Array
(
[name] => Array
(
[0] => img3.jpg
)
[type] => Array
(
[0] => image/jpeg
)
[tmp_name] => Array
(
[0] => /opt/lampp/temp/phpQNpdOb
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 144544
)
)
)
我也尝试了this SO post中提到的解决方案,但这也没有奏效。
PS:我不想通过ajax上传文件我只是想预览我选择的所有文件,当我按下提交按钮时,我想要上传所有这些文件。
我在这里做错了什么?