请问一下,怎样利用 ext 上传图片到数据库

解决方案 »

  1.   

    这是ext的前台写法,具体后台比较好接兄台就自己写吧var f=  new Ext.FormPanel({
     fileUpload: true,//允许文件上传
     frame: true,
     bodyStyle: 'padding: 10px',
       labelWidth: 80,
       defaults: {
                anchor: '95%',
                allowBlank: false,
                msgTarget: 'side'
            },
            items:
             {
                xtype: 'fileuploadfield',//设置上传的表单组件
                id: 'form-file',
                emptyText: '选择照片',
                fieldLabel: '照片路径',
                name: 'file1',
                buttonCfg: {
                    text: '选择' }
                }
    });
    var w = new Ext.Window({
    width:300,
    height:120,
    layout:"fit",
    title:"照片上传",
    modal:true,
    items:f,
    border:false,
    buttons:[{
    text:"上传",
    handler:function(){
    f.getForm().submit({
    waitTitle:"正在上传:", 
    waitMsg:"请稍后.....",//提交等待对话框内容
    /*提交的位置*/
    url:"<%=request.getContextPath()%>/CosUpLoad",
    /*成功的处理*/
    success:function(a,b){
    eval("var ming = "+b.response.responseText);
    //alert(ming.ming);
    fangNa.setValue(ming.ming);
    w.close();
    }, 
    failure :function(){
    Ext.Msg.alert("提示","保存失败");

    }//失败

    });
    }
    },
    {
    text:"取消",
    handler:function(){
    w.close();
    }
    }]
    })
    w.show();
     

    }    
      

  2.   


    前端代码:
    var UploadWin = new Ext.Window({
        title: "上传图片",
        layout: "fit",
        width: 260,
        height: 120,
        minWidth: 260,
        minHeight: 120,
        constrain: true,
        closeAction: "hide",
        resizable: true,
        minimizable: false,
        maximizable: false,
        buttonAlign: "center",
        modal: true,
        items: {
            xtype: "form",
            border: false,
            labelWidth: 60,
            bodyStyle: "padding:15px",
            fileUpload: true,
            items: {
                xtype: "fileuploadfield",
                fieldLabel: "文件名",
                name: "file-path",
                buttonText: '',
                buttonCfg: {
                    iconCls: "upload-icon"            }        }    },
        buttons: [
        {
            text: "确定",
            handler: function() {
                if (UploadWin.get(0).getForm().isValid()) {
                    UploadWin.get(0).form.submit({
                        clientValidation: true,
                        url: "",
                        params: {
                            action: ""
                        },
                        success: function(form, action) {
                            //上传成功后的操作
                            },
                        failure: function(form, action) {
                            }
                    });
                }
            }
        },
        {
            text: "取消",
            handler: function() {
                UploadWin.hide();
            }
        }
        ]});
    你还需要有后台代码
    其实数据库中最好是存图片的路径就可以了。
      

  3.   

    楼主需要下载
    FileUploadField.js
     这个是ext扩展的一个组件。google一下