在线编辑器CKEditor,多图上传功能实现

界面设计:

批量上传时:

下面是代码:

aspx 代码:

 1  <tr>
 2                         <td style="display: none">
 3                             <iframe src="/b2c/pages/common/uploadPic.aspx?type=202&editor=<%=txt_Description.ClientID %>&spuId=<%=hid_spuId.Value %>"
 4                                 scrolling="no" frameborder="0" height="50" width="400"></iframe>
 5                         </td>
 6                         <td style="display: ">
 7                             <input type="button" id="btnUpLoadImage" onclick="OpneImageDiv()" style="width: 120px"
 8                                 class="btn" value="批量上传图片" />
 9                         </td>
10                     </tr>
11                     <tr>
12                         <td>
13                             <CKEditor:CKEditorControl ID="txt_Description" name="content" runat="server" Width="100%"
14                                 Height="300px" TemplatesFiles="~/b2c/js/common/ckeditor/plugins/templates/templates/default.js"
15                                 onchange="unloadcheck=true;"></CKEditor:CKEditorControl>
16                         </td>
17                     </tr>

js 方法:

 1   <script type="text/javascript">
 2         $(function(){
 3            $("#divImage").dialog({ width: 600, height: 300, autoOpen: false, modal: true, title: ‘批量上传图片‘, draggable: false, resizable: false });
 4
 5         })
 6         //多图上传
 7         ///b2c/pages/common/uploadPic.aspx?type=202&editor=<%=txt_Description.ClientID %>&spuId=<%=hid_spuId.Value %>
 8          window.onload = function ()
 9          {
10             var spuId=‘<%=hid_spuId.Value %>‘;
11             //var editor=‘<%=txt_Description.ClientID %>‘;
12             var editor=‘<%=txt_Description_ClientID%>‘
13             var params =
14             {
15                 uploadServerUrl: "/b2c/pages/itemSPU/upload.aspx?SpuId="+spuId, //上传响应页面(必须设置)
16                 maxFileData: 1024 * 300,       //300KB
17                 jsFunction: "upload",         //上传成功后回调JS
18                 filter: "*.jpg;*.png;"        //上传文件类型限制
19             }
20             swfobject.embedSWF("/b2c/js/Flash/uploadImage.swf", "myContent", "580", "200", "10.0.0", "/b2c/js/Flash/expressInstall.swf", params);
21         }
22         function OpneImageDiv()
23         {
24             $("#divImage").dialog("open");
25         }
26         function upload()
27          {
28             $("#divImage").dialog("close");
29             $.ajax({
30                         type: "post",
31                         dataType:"json",
32                         data: {"type":1,"spuId":‘<%=hid_spuId.Value %>‘},
33                         url: "/b2c/handlers/Order/UpLoadImage.ashx",
34                         success: function(data)
35                         {
36                             var   strHTML="";
37                             var txt_Description=  $("#<%=txt_Description.ClientID %>").val();
38                             for(var i=0;i<data.length;i++)
39                             {
40                                 var imgURL=data[i].filePath;
41                                 var imgName=data[i].fileName;
42                                 strHTML+="<img src=‘"+imgURL+"‘/>";
43                             }
44                            // 给CKEDITOR赋值 ctl00_MainContent_txt_Description 服务端空间CKEDITOR的ClientID
45                             CKEDITOR.instances[‘ctl00_MainContent_txt_Description‘].insertHtml(strHTML)
46                         },
47                         error: function() {
48                             alert("请求异常");
49                         }
50                     });
51         }
52         </script>

服务端代码:

 1 {
 2         FileSettingEntity fileVaild = null;
 3         fileVaild = FileManger.GetFileSetting((int)ESourceType.fromSPUDescription);
 4         if (file.ContentLength > fileVaild.Length)
 5         {
 6             return "";
 7         }
 8         else
 9         {
10             FileEntity fentity = null;
11             try
12             {
13                 fentity = Gasgoo.B2C.Common.FileUpload.Upload(file, ESourceType.fromSPUDescription, SpuId.ToType<int>(), 0, true);
14
15             }
16             catch
17             {
18                 return "";
19             }
20             string ServiceImages = fentity.FileID + Path.GetExtension(Request.Form["fileName"].ToLower());
21             if (!String.IsNullOrEmpty(ServiceImages))
22             {
23                 return ServiceImages;
24             }
25             return "";
26         }
27     }

AJAX:

 1  context.Response.ContentType = "text/plain";
 2         #region 订单投诉跟进图片 add it by wangyy
 3         string kid = WebHelper.GetFormHtmlValue<string>("Kid", "");
 4         string imgs = CacheManager.CreateCache("Manage_Image_Upload").Get<string>(kid);
 5         CacheManager.CreateCache("Manage_Image_Upload").Remove(kid);
 6         #endregion
 7
 8
 9         #region SPU图片 add it by wangyy
10         string spuId = WebHelper.GetFormHtmlValue<string>("spuId", "");
11         string Spu_imgs = CacheManager.CreateCache("SPU_Image_Upload").Get<string>(spuId);
12         CacheManager.CreateCache("SPU_Image_Upload").Remove(spuId);
13         #endregion
14
15
16         // type  1:SPU商品详情图片 0:订单跟进投诉图片
17         int type = WebHelper.GetFormHtmlValue<int>("type", 0);
18         List<FileEntity> list = new List<FileEntity>();
19         string strJson = string.Empty;
20         strJson = "[";
21         if (type == 0)
22         {
23             list = FileFactory.GetItemImagesByFileArray(imgs, ESourceType.formOrderFollow);
24         }
25         else
26         {
27             list = FileFactory.GetItemImagesByFileArray(Spu_imgs, ESourceType.fromSPUDescription);
28
29         }
30         if (list != null && list.Count > 0)
31         {
32             foreach (FileEntity item in list)
33             {
34                 strJson += "{\"fileName\":\"" + item.FileName + "\",\"filePath\":\"" + item.ImageUrl + "\"},";
35             }
36         }
37         strJson = strJson.TrimEnd(‘,‘) + "]";
38         context.Response.Write(strJson);
39     }

      其中有很多框架中的代码引用,只提供一种思路,又不熟悉和有问题的地方请联系我 QQ:1627298416,欢迎指教

时间: 2024-08-03 18:08:19

在线编辑器CKEditor,多图上传功能实现的相关文章

dedecmsV5.7 百度编辑器ueditor 多图上传 在线管理 排序问题

问题:dedecms后台百度编辑器ueditor的多图上传-在线管理的图片排序有问题,想把这个顺序调成按照文件修改时间倒序来展示 解决方法: 1.打开/include/ueditor/php/aciton_list.php 在最后添加下面这个方法 function array_sort($array,$row,$type){ $array_temp = array(); $arr=array(); foreach($array as $v){ $array_temp[$v[$row]] = $v

在线编辑器Ckeditor (1) - php (30)

在线编辑器 在线编辑器也称之为所见即所得编辑器,是一种常见的html源码编辑器. 所见即所得:用户在输入的时候,不论是格式和是样式都能被系统原封不动的保存,最后在查看的时候,可以按照用户输入的原来的结构进行输出. 在线编辑器分类 市面上比较常见的在线编辑器有很多,FCKeditor(在线编辑器+Ajax浏览器端服务器文件管理器,免费的),Ckeditor(Content and Knowledge,在线编辑器与服务器端文件管理器分离,在线编辑器免费,服务器端文件管理器收费(CKfinder)),

百度Ueditor编辑器取消多图上传对话框中的图片搜索

百度Ueditor确实是一个非常强悍的编辑器,功能强大!但是实际开发需求复杂,总会有各种不符合要求的,比如想要取消多图上传的“图片搜索”选项卡(这个图片搜索真心难用)! 以ueditor 1.4.3为例: 1.打开ueditor1.4.3\dialogs\image\image.html 2.删除第25行 <span class="tab" data-content-id="search"><var id="lang_tab_search

在线编辑器Ckeditor (2) - php (31)

接上一篇 3 in-page(页内)配置,在使用Ckeditor的界面里进行直接配置 页内配置 效果 特点:配置项完全属于某个特定的Ckeditor实例,不可重用 三种配置方式比较 定制方式 特点 说明 优先级 接口函数 灵活,不能复用 每个使用编辑器的页面都要写一次代码 最高 覆盖自定义及系统配置文件中的参数 自定义配置文件 灵活,可复用 可根据使用场景定义多个自定义配置文件,在不同的页面中引用不同的配置文件 中等 覆盖系统配置文件中的参数 系统配置文件 不灵活 全局性质,影响所有程序 最低

在线编辑器ckeditor配置与使用

1.去官网下载http://ckeditor.com/合适的版本,我用的是最新版,ckeditor_4.5.6_standard 2.将解压的文件夹复制到WebContent文件夹下(本人IDE的是Eclipse) 3.jsp页面引入 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/samples.css"> <script src="${pageCo

CKedit在线编辑器

在线编辑器???? ????在实现所见即得的编辑效果. FCK????????????是开发者的名字的缩写 CKEditor????????功能很完善的,具有,在线编辑与图片上传JS插件 UEdit????????????百度自己开发的一款在线编辑器 ? CKeditor安装 http://resource.ckeditor.com/ basic package????????基本安装包????????只包含了基本的功能 standard package????标准安装包????????包含更多

项目整合ckeditor实现图片上传到远程服务器

最近手头上的一个Java项目需要做一个门户网站,其中有一个模块就是用来发布最新的业界安全动态的模块,因此需要用到后台发布新闻的功能:刚开始的时候在网上搜了一下,大部分都是关于PHP和.NET的,关于Java不多,而且查到的都是说用ckeditor+ckfinder来实现,ckeditor实现文本的编辑,ckfinder实现图片的上传,刚开始我也是准备用ckeditor+ckfinder来实现的,但是后来研究ckfinder的时候不知道如何配置ckfinder的图片上传路径问题,网上可以找到好多例

drupal中安装CKEditor文本编辑器,并配置图片上传功能 之 方法二

drupal中安装CKEditor文本编辑器,并配置图片上传功能 之 方法一 中介绍了ckeditor的安装和配置方法,其实还有另一种新方法,不用IMCE模块. 不过需要ckfinder的JS库,可以到http://ckfinder.com/download下载,下载后放到ites\all\modules\contrib\ckeditor文件夹下如图, 然后到admin/config/content/ckeditor/edit/Full配置一下 就行了

jsp解决kindeditor在线编辑器struts图片上传问题

1.下载 官网下载ckeditor,解压后去掉不需要的部分,仅需保留plugin,lang,theme文件夹,这三个文件夹中用不到的东西可以删除, 比如lang文件下存放所有语言文件js,仅仅 保留en.js和zh_CN.js即可,保留jsp文件夹下的json_upload.jsp文件和 kindeditor.js文件即可,把jsp下面的jar导入 在线编辑器:http://kindeditor.net/ 2.修改json_upload.jsp 修改json_upload.jsp文件保存路径即可