extjs的文件上传 跪求高手解答

尘缘未了_情 发布于 2014/07/07 17:54
阅读 1K+
收藏 0
在Extjs中filefield组件的hideLabel我设置为true;就只剩下一个按钮,我在按钮中写了一个change事件;点打开文件时直接跳后台;我现在要的结果是把我选中的文件传到后台,不是传路径,这个需要怎么写才能让后台得到那个文件呢???
加载中
0
Ryan-瑞恩
Ryan-瑞恩
Ext.create('Ext.form.Panel', {
    title: 'Upload a Photo',
    width: 400,
    bodyPadding: 10,
    frame: true,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'filefield',
        name: 'photo',
        fieldLabel: 'Photo',
        labelWidth: 50,
        msgTarget: 'side',
        allowBlank: false,
        anchor: '100%',
        buttonText: 'Select Photo...'
    }],


    buttons: [{
        text: 'Upload',
        handler: function() {
            var form = this.up('form').getForm();
            if(form.isValid()){
                form.submit({
                    url: 'photo-upload.php',
                    waitMsg: 'Uploading your photo...',
                    success: function(fp, o) {
                        Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
                    }
                });
            }
        }
    }]
});
0
C
ChooseYou
你在items里面加个inputType='file'试下
0
唐代de豆腐
唐代de豆腐

哥们,我来告诉你一下,

首先,你要用formPanel 并设置属性: fileUpload:true,  

另外,对于上传使用原组件:

  1.  {  
  2.                                 xtype:'textfield',  
  3.                                 allowBlank:false,  
  4.                                 fieldLabel:'选择文件',  
  5.                                 inputType:'file',  
  6.                                 name:'fileName'  
  7.                             }  
 提交一般如下:

  1. if(fpFileUpload.form.isValid()){  
  2.                                         fpFileUpload.form.submit({  
  3.                                             method:'post',  
  4.                                             url:'Default.aspx',  
  5.                                             waitMsg:'文件上传中...',  
  6.                                             success: function() {  
  7.                                                 Ext.Msg.alert("系统提示", "文件上传成功!");  
  8.                                             },  
  9.                                             failure: function() {  
  10.                                                 Ext.Msg.alert("系统提示", "文件上传失败!");  
  11.                                             }  
  12.                                         });  
  13.                                     }else{  
  14.                                         Ext.Msg.alert("系统提示","请选择文件后再上传!");  
  15.                                     }  

返回顶部
顶部