【问题标题】:ExtJS 4.2 filefield multiple uploadExtJS 4.2 文件字段多重上传
【发布时间】: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后检索所有文件?

【问题讨论】:

    标签: extjs extjs4.2


    【解决方案1】:

    你可以命名你的文件字段,这样它就可以将 name 属性添加到底层的 html 输入中。

    ...
    xtype: 'filefield',
    name: 'uploads[]',
    fieldLabel: '',
    ...
    

    然后你可以在 PHP 上使用;

    $_FILES["uploads"];
    

    【讨论】:

    • 非常感谢,现在我可以访问我的 php 中的所有文件了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    相关资源
    最近更新 更多