CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)
参考博客:http://blog.csdn.net/mydwr/article/details/8669594
本人版本:4.4.6
打开文件:ckeditor/plugins/image/dialogs/image.js
搜索内容:【c.config.image_previewText】,并删掉其后引号内的内容。
删除后格式:【c.config.image_previewText||""】。
与原文差异:原内容原文中是【b.config.image_previewText】,我这里是【c.config.image_previewText】,可能是版本不同的原因;原文中包括其后内容的包括号是单引号,我的版本是双引号,不影响使用。
修改影响:预览界面中杂乱的字符消失。
搜索内容:“upload”,并找到:【id:"Upload",hidden:!0】。
替换内容:将hidden的值改为0。
与原文差异:原文hidden后的值是true,我这里是非0。
修改影响:编辑器图片界面的上传按钮及选项卡出现。
打开文件:ckeditor/config.js文件
在配置的最后添加一条【config.filebrowserImageUploadUrl = "【ashx上传处理页面路径】";】
如果只是进行以上的设置的话,在图片上传完毕之后,会提示【缺少图像源文件地址】。
为了使其正常运行,则需要在图片上传成功的返回值中添加script将图片地址输入预览当中。
代码如下【注意将uploadImages/替换为图片存储的文件夹,modifiedName替换为上传后存储的文件名】:
context.Response.Write("<script type=\"text/javascript\">");
context.Response.Write("window.parent.CKEDITOR.tools.callFunction(" + callbackNumber + ",'" + "uploadImages/" + modifiedName + "','')");
context.Response.Write("</script>");
一定要将context.Response.ContentType设置为"text/html",而不是默认的"text/plain",返回的值才会是html代码而不是不能运行的纯字符串。
ashx上传处理页面如下【我的处理比较繁琐,各位可自行简化】:
public class UploaderHandler : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html"; //对文件进行校验
if ( > context.Request.Files.Count)
{
ResponseWriteEnd(context, "<span style='color: red; font-size: 20px;'>*请选择上传文件!</span>");
return;
}
else
{
HttpPostedFile _upfile = context.Request.Files[];
string fileName = _upfile.FileName;
string fileType = fileName.Substring(fileName.LastIndexOf(".") + ).ToLower();
int imgLength = _upfile.ContentLength;//获取文件的字节大小 if (!(fileType.Equals("jpg") || fileType.Equals("png") || fileType.Equals("bmp") || fileType.Equals("gif")))
{
ResponseWriteEnd(context, "<span style='color: red; font-size: 20px;'>*只能上传jpg/png/bmp/gif格式的图片!</span>"); //只能上传JPG格式图片
return;
}
else
{
if (imgLength > * * )
{
ResponseWriteEnd(context, "<span style='color: red; font-size: 20px;'>*图片最大不能超过5M!</span>"); //图片不能大于5M
return;
}
else
{
try
{
// 构造简单的防重复文件名
string callbackNumber = context.Request.QueryString["CKEditorFuncNum"];
string modifiedName = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss_") + fileName;
string savePathName = context.Server.MapPath("uploadImages/" + modifiedName);
_upfile.SaveAs(savePathName);
if (_upfile.InputStream != null)
{
_upfile.InputStream.Close();
}
// 上传结束后自动跳转到预览界面,并显示预览
context.Response.Write("<script type=\"text/javascript\">");
context.Response.Write("window.parent.CKEDITOR.tools.callFunction(" + callbackNumber + ",'" + "uploadImages/" + modifiedName + "','')");
context.Response.Write("</script>");
ResponseWriteEnd(context, "<span style='font-size: 20px;'>上传成功!</span>"); //上传成功
return;
}
catch
{
ResponseWriteEnd(context, "<span style='color: red; font-size: 20px;'>服务器内部错误!</span>");
return;
}
}
}
}
} public bool IsReusable
{
get
{
return false;
}
} private void ResponseWriteEnd(HttpContext context, string message)
{
context.Response.Write(message);
context.Response.End();
}
}
CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)的更多相关文章
- easyui+webuploader+ckeditor实现插件式多图片上传-添加图片权限(图片上传人是谁,只能看到自己的图片)
需求: 实现过程及思路 1.先页面布局 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=" ...
- easyui+webuploader+ckeditor实现插件式多图片上传
需求:在ckeditor编辑器上实现多图片上传并要求另外单独选择ckeditor上传的图片作为封面 页面效果说明: 动态效果图: 第一步:页面布局 <html xmlns="http: ...
- 在ASP.NET项目中使用CKEditor +CKFinder实现图片上传功能
前言 之前的项目中一直使用的是FCKeditor,昨天突然有个想法:为什么不试一下新的CKEditor呢?于是花了大半天的时间去学习它的用法,现在把我的学习过程与大家分享一下. 谈起FCKeditor ...
- PHP ckeditor富文本编辑器 结合ckfinder实现图片上传功能
一:前端页面代码 <script src="/www/res/ckeditor/ckeditor.js"></script> <textarea id ...
- .net_ckeditor+ckfinder的图片上传配置
CKEditor和CKFinder的最新版可以到官方网站(http://cksource.com)上下载获得. 把以上两个资源放到网站的根目录: /CKEditor 和 /CKFinder (不区分大 ...
- h5图片上传简易版(FileReader+FormData+ajax)
一.选择图片(input的file类型) <input type="file" id="inputImg"> 1. input的file类型会渲染为 ...
- ci 配置ckeditor + ckfinder 无图片上传按钮
一:配置路径有问题 {$base_url}assets/js/editor/ckfinder/ckfinder.html --> http://www.cnblogs.com/assets/j ...
- jsp中如何整合CKEditor+CKFinder实现文件上传
最近笔者做了一个新闻发布平台,放弃了之前的FCKEditor编辑器,使用了CKEditor+CKFinder,虽然免费的CKFinder是Demo版本,但是功能完整,而且用户都是比较集中精神发新闻的人 ...
- UMEditor(Ueditor mini)修改图片上传路径
UMEditor(Ueditor mini)修改图片上传路径 imageUp.ashx string pathbase = "/UpLoad/images/"; //保存文件夹在网 ...
随机推荐
- js高程(二)-----继承
首先来讨论一下原型链,上代码 function SuperType(){ this.property = true; } SuperType.prototype.getSuperValue = fun ...
- MySql Table错误:is marked as crashed and last (automatic?) 和 Error: Table "mysql"."innodb_table_stats" not found
一.mysql 执行select 的时候报Table错误:is marked as crashed and last (automatic?) 解决方法如下: 找到mysql的安装目录的bin/myi ...
- 零基础入门学习UI设计指南
第一步:认识设计启蒙必备知识 学习一项技能,尤其是已经有一定沉淀并在各行各业有广泛应用的技能,就一定要对它先有充分的认知.在开始正式学习前,你需要花足够的经历去了解和查阅它的起源.发展.应用.未来. ...
- Flask入门笔记(一)
一.程序的基本结构 1.1 最简单的Flask程序 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #coding=utf-8 # 初始化 from flask import Fla ...
- 浩哥解析MyBatis源码(二)——Environment环境
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6625612.html 本应该先开始说Configuration配置类的,但是这个类有点过于 ...
- ECMAScript版本号总结
最近想要研究下ES6,关于这个标准的发展历史.ES5. ES6.ES2015等等名称的定义都不怎么明确,查了很多资料,去除了程序员不关心的信息,下面是对ECMAScript规范发展历史及名词定义的 ...
- PHPSTORM下安装XDEBUG
本文不是教程安装XDEBUG,具体的请自行百度(我也是按照百度上的一步步来的). 以下纠正几点目前我安装时查看播客的不对之处: 1. Setting > PHP > DEBUG > ...
- OpenStack_Glance
什么是Glace Glance即image service(镜像服务),就是为创建虚拟机提供镜像的地方 为什么要有Glance 这个问题问的好,openstack就是构建Iaas平台对外提供虚拟机的啊 ...
- 【2017-03-31】JS-DOM操作:操作属性、彩虹导航栏、定时器、操作内容、创建元素并添加、操作相关元素
一.操作属性 1.什么是属性: <div class="div" id="div1" style="" ></div> ...
- Confluence安装&破解&汉化
p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; f ...