Ext4.x之HtmlEditor扩展图片上传功能

1.实现非常简单,稍后跟上,废话不说先上图。

2.类的定义:

Ext.define(‘Ext.ux.XHtmlEditor‘,{
        extend:‘Ext.form.field.HtmlEditor‘,
        alias:‘widget.xhtmleditor‘,
        //扩展的属性
        uploadConfig:{
            url:‘‘//后台上传地址
        },
        initComponent : function(){
            this.callParent(arguments);
            var me = this;
            //创建组件
            me.initExtFun = function(){
                Ext.create(‘Ext.window.Window‘,{
                    title:‘插入图片‘,
                    resizable:false,
                    border:false,
                    modal:true,
                    frame:false,
                    iconCls:‘Picture-Sunset‘,
                    items:[
                        {
                            xtype:‘form‘,
                            width:320,
                            height:70,
                            padding:10,
                            border:false,
                            items:[
                                {
                                    width:280,
                                    labelAlign:‘right‘,
                                    labelWidth:60,
                                    xtype:‘filefield‘,
                                    name:‘file‘,
                                    allowBlank:false,
                                    fieldLabel:‘选择图片‘,
                                    buttonText:‘浏览...‘
                                }
                            ]
                        }
                    ],
                    buttons:[
                        {
                            text:‘上传‘,
                            handler:function(b,e){
                                //实现上传,完成之后插入带编辑器
                                var form = b.up(‘window‘).down(‘form‘);
                                form.submit({
                                    waitMsg:‘正在上传...‘,
                                    clientValidation: true,
                                    url:me.uploadConfig.url,
                                    success:function(form,action){
                                        //返回图片路径
                                        var path = action.result.message;
                                        //将图片插入到光标所在的位置
                                        me.insertAtCursor("<img src=‘"+path+"‘ />");
                                        b.up(‘window‘).close();
                                    },
                                    failure:function(form,action){
                                            switch (action.failureType) {
                                                case Ext.form.action.Action.CLIENT_INVALID:
                                                    Ext.Msg.alert(‘提示‘,‘客户端验证不通过!‘);
                                                    break;
                                                default:
                                                    Ext.Msg.alert(‘保存失败,‘,action.result.message);
                                            }
                                        }
                                    });
                            }
                        },
                        {
                            text:‘取消‘,
                            handler:function(b,e){
                                b.up(‘window‘).close();
                            }
                        }
                    ]
                }).show();
            }
            var b = Ext.create(‘Ext.button.Button‘,{
                xtype:‘button‘,
                iconCls:‘Picture-Sunset‘,
                tooltip:‘上传图片‘,
                text:‘‘,
                listeners:{
                    click:function(b,e){
                         me.initExtFun();
                    }
                }
            });
            me.getToolbar().add(b);
        }
    });
    

3.用法很简单,首加载在上面的类,然后这样引用。xtype:‘xhtmleditor‘

          {
                        xtype:‘xhtmleditor‘,
                        uploadConfig:{
                            url:‘/app/uploadImage‘
                        }
                 }

4.后台实现上传就省了,方法贼多。但要注意的是后台默认接收图片的name是file,在上面类中有定义,可以随意改。

时间: 2025-01-07 14:13:03

Ext4.x之HtmlEditor扩展图片上传功能的相关文章

thinkphp实现UploadFile.class.php图片上传功能

图片上传在网站里是很常用的功能.ThinkPHP里也有自带的图片上传类(UploadFile.class.php) 和图片模型类(Image.class.php).方便于我们去实现图片上传功能,下面是实现方法 1.我们首先需要创建一个表 复制代码代码如下: CREATE TABLE IF NOT EXISTS `tp_image` ( `id` int(11) NOT NULL AUTO_INCREMENT, `image` varchar(200) NOT NULL, `create_time

(转)淘淘商城系列——实现图片上传功能

http://blog.csdn.net/yerenyuan_pku/article/details/72808000 上文我们使用FastDFS-Client进行了简单的文件上传操作测试,淘淘商城项目中添加商品时上传图片的功能还没实现,如下图所示.本文将花大量笔墨来教大家如何实现图片上传这个功能. 我们来看下item-add.jsp页面,可以看到上传图片触发的方法是通过叫做picFileUpload的class来处理的,在<a>标签的下方是一个隐藏域,是用来接收图片上传到图片服务器的回显地址

在SAE上使用Ueditor的图片上传功能

SAE上是没有目录读写权限的,所以要在SAE使用Ueditor的图片上传功能需要借助SAE的Storage服务. 一.开通Storage服务 在SAE控制台开通Storage服务,并新增一个domain. 二.修改Ueditor代码 Ueditor处理上传文件的方法在DjangoUeditor/jviews.py中,上传图片的请求是由下面函数处理的 #上传附件 @csrf_exempt def UploadFile(request,uploadtype,uploadpath):     '''

用jsp实现简单的图片上传功能(multipart/form-data形式的表单)

2008-10-11 22:07 用jsp实现简单的图片上传功能 1 先做一个页面,选择上传的图片<body>   <form action="uploadServlet" enctype="multipart/form-data" method="POST" >           selectimage: <input type="file" name="myfile"/&

jq图片上传功能

//图片上传功能jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(this); opts = jQuery.extend({ Img: "ImgPr", Width: 100, Height: 100, ImgType: ["gif", "jpeg", "jpg", "bmp", "png

vue 图片上传功能

这次做了vue页面的图片上传功能,不带裁剪功能的! 首先是html代码,在input框上添加change事件,如下: <ul class="clearfix">   <li v-if="imgs.length>0" v-for='(item ,index ) in imgs'>   <img :src="item">   </li>   <li style="position:

给DEDECMS广告管理中增加图片上传功能

dedecms的广告管理功能稍微有点次,本文就是在dedecms广告管理原有的基础上增加广告图片上传功能. 安装方法,对应自己的dedecms版本下载对应的编码然后解压把里面的文件放在后台目录覆盖即可. 效果图: 原文地址:https://www.cnblogs.com/liu-zhijun/p/11404535.html

java web开发 图片上传功能

基本思路在于,配置路径,然后用java I/O的api将图片上传到该目录下. String photoPath =    ServletActionContext.getServletContext().getRealPath("/user/photo/" + username); 这句是获取服务器下的目录+username 而username通过session获取. 这是一个图片上传action的方法: public String execute() throws Exception

单独调用Ueditor的图片上传功能

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <script src="/scripts/jquery-1.8.3.min.js"></script> 6 <script src="/ueditor/ueditor.config.js" type="text/javascript">&l