kindeditor编辑器上传图片
使用的是asp.net MVC 上传图片。
1.下载Kindeditor的对应的包
2.html页面
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>UploadByKindeditor</title>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Content/KindEditor/kindeditor.js"></script>
<script src="~/Content/KindEditor/plugins/image/image.js"></script>
<script type="text/javascript">
var editor;
var options = {
uploadJson: '/BusinessPublic/UploadImage', // (BusinessPublic,UploadImage为Action,下同) 上传图片
fileManagerJson: '/BusinessPublic/UploadFile', //上传文件
allowFileManager: true,
width: "100%", //编辑器的宽度为100%
height: "250px", //编辑器的高度为100px
filterMode: false, //不会过滤HTML代码
resizeMode: 1 //编辑器只能调整高度
};
$(function () {
editor = KindEditor.create('#content', options);
});
</script>
</head>
<body>
<div>
内容:<textarea id="content" name="content" style="height:300px;"></textarea>
</div>
</body>
</html>
3.后台Action代码: 使用post提交 (上传文件都是使用post方式)
[HttpPost]
public ActionResult UploadImage()
{ string savePath = "/Resource/KindeditorImage/"; string fileTypes = "gif,jpg,jpeg,png,bmp"; int maxSize = ; Hashtable hash = new Hashtable(); HttpPostedFileBase file = Request.Files["imgFile"]; if (file == null)
{ hash = new Hashtable(); hash["error"] = ; hash["url"] = "请选择文件"; return Json(hash); } string dirPath = Server.MapPath(savePath); if (!Directory.Exists(dirPath))
{ Directory.CreateDirectory(dirPath); } string fileName = file.FileName; string fileExt = Path.GetExtension(fileName).ToLower(); ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); if (file.InputStream == null || file.InputStream.Length > maxSize)
{ hash = new Hashtable(); hash["error"] = ; hash["url"] = "上传文件大小超过限制"; return Json(hash); } if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring().ToLower()) == -)
{ hash = new Hashtable(); hash["error"] = ; hash["url"] = "上传文件扩展名是不允许的扩展名"; return Json(hash); } string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; string filePath = dirPath + newFileName; file.SaveAs(filePath); //图片在服务器上的路径
string fileUrl = savePath + newFileName; hash = new Hashtable(); hash["error"] = ; hash["url"] = fileUrl; return Json(hash, "text/html;charset=UTF-8"); ; }
PS:
(3)返回Json的信息:
//成功时 { "error" : 0, "url" : "http://www.example.com/path/to/file.ext" }
//失败时 { "error" : 1, "message" : "错误信息" }
(2)编写服务器端图片上传方法,要求返回的结果为JSON格式
kindeditor编辑器上传图片的更多相关文章
- kindeditor编辑器上传图片失败 错误 405.0解决办法(亲测)
HTTP 错误 405.0 - Method Not Allowed(省略)editor/php/upload_json.php?dir=image物理路径 http://www.gdgoga.com ...
- Django项目开发,XSS攻击,图片防盗链,图片验证码,kindeditor编辑器
目录 一.Django项目开发 1. 项目开发流程 2. auth模块的补充 (1)django的admin可视化管理页面 (2)将admin可视化管理页面的模型表显示成中文 (3)auth模块的用户 ...
- 如何自定义kindeditor编辑器的工具栏items即去除不必要的工具栏或者保留部分工具栏
kindeditor编辑器的工具栏主要是指编辑器输入框上方的那些可以操作的菜单,默认情况下编辑器是给予了所有的工具栏.针对不同的用户,不同的项目,不同的环境,可能就需要保留部分工具栏.那么我们应该如何 ...
- ThinPHP第二十八天(F函数和file_put_contents区别|PHP生成PHP文件,Kindeditor编辑器使用方法)
1.F(name,data,path)函数和file_put_contents(file,str)区别 F函数直接生成<?php ?>格式的php文件了,将data加入到<?php和 ...
- 在MVC3中修改KindEditor实现上传图片到指定文件夹
KindEditor编辑器默认上传的图片文件夹,是根据系统时间自动生成的,图片是自动上传到这些文件夹里面,无法选择.如果要上传图片到指定文件夹,像相册一样管理图片,则需要扩展KindEditor编辑器 ...
- Kindeditor编辑器上传附件,自动获取文件名显示。
大部分在线编辑器在上传附件之后都是会以路径的形式显示出来很不友好.类似这样..怎么样显示成这样用户上传的原始文件名呢.就是这样.是不是看着很友好. kindeditor编辑器上传文件是已插件的形式调用 ...
- kindeditor编辑器和图片上传独立分开的配置细节
关于kindeditor编辑器上传按钮的异步加载最关键的部署问题,它的上传图片的组件都已经封装得很好了的,只需要监听到页面按钮的点击事件给编辑器对象传递一些对应的初始化参数即可显示图片上传的弹窗实现异 ...
- 如何在一个页面添加多个不同的kindeditor编辑器
kindeditor官方下载地址:http://kindeditor.net/down.php (入门必看)kindeditor官方文档:http://kindeditor.net/doc.ph ...
- kindeditor编辑器里面 filterMode为false时候,允许输入任何代码
kindeditor编辑器里面 filterMode为false时候,允许输入任何代码
随机推荐
- Linux安装Gitlab,附iSCSI分区挂载说明
因为Gitlab数据要存放在共享存储,所以本次配置的重头戏倒变成了挂载ISCSI了. OS:CentOS 7.2IP:172.16.1.191/192.168.2.191 iSCSI分Target(服 ...
- jpa 原生查询createNativeQuery里面有冒号保留字关键字的问题
用\\:替换. 比如: String sql = "select location.ToString() a,version,location.STDistance(geometry\\:\ ...
- LOJ#2306 蔬菜
补充一个题意不太清楚的地方:蔬菜坏掉是假设蔬菜都有标号,那么特定标号的蔬菜就会在特定时间坏掉.如果你及时卖了它们,那么那一天就不会有新的蔬菜坏掉. 结论1:如果我们知道了k天的答案,那么我们直接扔掉若 ...
- A1143. Lowest Common Ancestor
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...
- php5.4后htmlspecialchars输出为空的问题
从旧版升级到php5.4,恐怕最麻烦的就是htmlspecialchars这个问题了!当然,htmlentities也会受影响,不过,对于中文站来说一般用htmlspecialchars比较常见,ht ...
- (map,c_str())水果 hdu1263
水果 http://acm.hdu.edu.cn/showproblem.php?pid=1263 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- php中函数里面使用函数外面的变量
一定要在函数里面声明为全局变量!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(不然会有问题,还是不报错的那种)
- 正则表达式(_ % regexp_like)
'[^\.0-9]'——不含小数点和数字的字符串,^在中括号内表非 select '123' aa from dual where regexp_like( '123', '[^\.0-9]' ) - ...
- qml性能优化(来源于群友分享);
Qt quick性能优化 使用时间驱动 避免定时轮询: 使用信号槽形式: 使用多线程 C++; QML WorkerScript元件: 使用Qt Quick Compiler 只需要再PRO文件中添加 ...
- 写给IT技术爱好者的一封信
写给IT技术爱好者的一封信>当前运维素质的分析<... ---------------------- 虽相貌平平,但勤学苦练,亦收获颇丰!如果你决定要成为一名IT从业者,你需要承受以下的东 ...