【发布时间】:2017-03-23 11:39:16
【问题描述】:
我在上传多文件时遇到了一些问题
在我的控制器中,我生成了一个带有表单的窗口,该表单有一个文件字段和一个网格:
var ventanaSubirDocumento=new Ext.Window({
title: '<span style="color:#C85E00;">Subida de Documento</span>',
plain: true,
modal: true,
frame: true,
border: false,
resizable: false,
draggable: false,
scope:this,
items:[
{
xtype:'form',
width: 400,
bodyPadding: 10,
frame: true,
timeout:600000,//Por si pesa mucho el archivo
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: '',
fieldLabel: '',
fieldStyle:'color:black',
labelWidth: '',
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Seleccionar documento',
listeners: {
change: function(fld, value) {
//var newValue = value.replace(/C:\\fakepath\\/g, '');
//fld.setRawValue(newValue);
var upload = fld.fileInputEl.dom;
var files = upload.files;
var names = [];
var names2 = [];
if (files) {
for (var i = 0; i < files.length; i++){
names.push(files[i].name);
names2.push({archivo:files[i].name})
value = names.join(', ');
}
}
gridDocumentos.getStore().loadData(names2);
fld.setRawValue(value);
},
/*render:function(field, eOpts){
field.fileInputEl.set({ multiple: true });
}*/
afterrender:function(cmp){
cmp.fileInputEl.set({
multiple:'multiple'
});
}
}
},
gridDocumentos
],
buttons: [{
text: 'Subir documento',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: 'data/php/Tmc_SubirDocumento.php',
waitMsg: 'Subiendo documento...',
success: function(fp, o) {
ventanaSubirDocumento.close();
Ext.Msg.show({
title: 'Subida de documento',
msg: 'Documento subido',
icon: Ext.MessageBox.INFO,
buttons: Ext.Msg.OK
});
}
}
}
}]
]
}).show();
在控制器中一切正常,如果我选择 1、2、3 等...文件上传网格填充其名称。
当我提交表单并执行 PHP 以处理所选文件时,问题就出现了,如果我在 php 中打印 $_FILES 变量,我只会得到最后一个选择。
在我的 request payload 中的 php 中,我看到了三个文件,但 $_FILES 只有最后一个:
------WebKitFormBoundaryJhIv2MXqKkzPnNys 内容处置:表单数据; name="filefield-1459-inputEl";文件名=“文件1.doc” 内容类型:application/msword
------WebKitFormBoundaryJhIv2MXqKkzPnNys 内容处置:表单数据; name="filefield-1459-inputEl";文件名="文件2.docx" 内容类型:application/vnd.openxmlformats-officedocument.wordprocessingml.document
------WebKitFormBoundaryJhIv2MXqKkzPnNys 内容处置:表单数据; name="filefield-1459-inputEl";文件名="file3.docx" 内容类型:application/vnd.openxmlformats-officedocument.wordprocessingml.document
我是否遗漏了什么?如何在php文件中提交formsubmit后检索所有文件?
【问题讨论】: