使用的是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:

通过KindEditor实现图片上传功能步骤:
 
(1)修改../plugins/image.js文件中fileName类型为file的name
 
 (2) 添加上传处理的URL:
 
 var editor;
     KindEditor.ready(function(K) {
 
         editor = K.create('#myeditor', 
 
        {
             uploadJson : '/uploadImg'
         });
 
  });
 

(3)返回Json的信息:

 
//成功时 { "error" : 0, "url" : "http://www.example.com/path/to/file.ext" }
//失败时 { "error" : 1, "message" : "错误信息" }
 
以下为老版本设置方法(过时):
------------------------------------------------------------------------------------------------
 
(1)修改../plugins/image.html文件中input类型为file的name
 

(2)编写服务器端图片上传方法,要求返回的结果为JSON格式

 
(3)JSON格式要求为:
 
{"error":0,"message":".....","url":"/img/1111.gif"} 
 
其中当error值为0时表示上传成功,需要指定url值为图片保存后的URL地址,如果error值不为0,则设置message值为错误提示信息
 
(4)Html页面:
 
//编辑器初始化设置
 
KE.show({
    id : 'editor',
    allowUpload : true, //允许上传图片
    imageUploadJson : '/saveImg' //服务端上传图片处理URI
});
 
//这里需要表单
<textarea id="editor" name="content" style="width:700px;height:300px;"></textarea>
 
 
(5)结束,就这么简单
 
注意:别忘了导入plugins/image文件夹,否则图片上传按钮无效。

kindeditor编辑器上传图片的更多相关文章

  1. kindeditor编辑器上传图片失败 错误 405.0解决办法(亲测)

    HTTP 错误 405.0 - Method Not Allowed(省略)editor/php/upload_json.php?dir=image物理路径 http://www.gdgoga.com ...

  2. Django项目开发,XSS攻击,图片防盗链,图片验证码,kindeditor编辑器

    目录 一.Django项目开发 1. 项目开发流程 2. auth模块的补充 (1)django的admin可视化管理页面 (2)将admin可视化管理页面的模型表显示成中文 (3)auth模块的用户 ...

  3. 如何自定义kindeditor编辑器的工具栏items即去除不必要的工具栏或者保留部分工具栏

    kindeditor编辑器的工具栏主要是指编辑器输入框上方的那些可以操作的菜单,默认情况下编辑器是给予了所有的工具栏.针对不同的用户,不同的项目,不同的环境,可能就需要保留部分工具栏.那么我们应该如何 ...

  4. ThinPHP第二十八天(F函数和file_put_contents区别|PHP生成PHP文件,Kindeditor编辑器使用方法)

    1.F(name,data,path)函数和file_put_contents(file,str)区别 F函数直接生成<?php ?>格式的php文件了,将data加入到<?php和 ...

  5. 在MVC3中修改KindEditor实现上传图片到指定文件夹

    KindEditor编辑器默认上传的图片文件夹,是根据系统时间自动生成的,图片是自动上传到这些文件夹里面,无法选择.如果要上传图片到指定文件夹,像相册一样管理图片,则需要扩展KindEditor编辑器 ...

  6. Kindeditor编辑器上传附件,自动获取文件名显示。

    大部分在线编辑器在上传附件之后都是会以路径的形式显示出来很不友好.类似这样..怎么样显示成这样用户上传的原始文件名呢.就是这样.是不是看着很友好. kindeditor编辑器上传文件是已插件的形式调用 ...

  7. kindeditor编辑器和图片上传独立分开的配置细节

    关于kindeditor编辑器上传按钮的异步加载最关键的部署问题,它的上传图片的组件都已经封装得很好了的,只需要监听到页面按钮的点击事件给编辑器对象传递一些对应的初始化参数即可显示图片上传的弹窗实现异 ...

  8. 如何在一个页面添加多个不同的kindeditor编辑器

    kindeditor官方下载地址:http://kindeditor.net/down.php    (入门必看)kindeditor官方文档:http://kindeditor.net/doc.ph ...

  9. kindeditor编辑器里面 filterMode为false时候,允许输入任何代码

    kindeditor编辑器里面 filterMode为false时候,允许输入任何代码

随机推荐

  1. MessageDigest来实现数据加密

    MessageDigest MessageDigest 类为应用程序提供信息摘要算法的功能,如 MD5 或 SHA 算法.信息摘要是安全的单向哈希函数,它接收任意大小的数据,输出固定长度的哈希值. M ...

  2. bzoj2553 禁忌

    题目链接 题意 给出一个\(n\)个字符串的字典.对于一个字符串,他的贡献是这个字符串中最多的在字典中出现的不重叠子串的数量. 然后问一个长度为\(len\)的,字符集为前\(alphabet\)个字 ...

  3. 【洛谷P1059 明明的随机数】

    题目描述明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着 ...

  4. python学习笔记—Day1

    1. python使用<变量名>=<表达式>的方式对变量进行赋值 a=1; python中数分为整数和浮点数 字符串的定义一定要用引号,单引号和双引号是等价的 三引号用来输入包 ...

  5. Java 实例 - 如何执行指定class文件目录(classpath) Java 实例 J

    Java 实例 - 如何执行指定class文件目录(classpath)  Java 实例 如果我们 Java 编译后的class文件不在当前目录,我们可以使用 -classpath 来指定class ...

  6. app软件遵循的规范

    http://www.jianshu.com/p/a2a4c18c1900 https://wenku.baidu.com/view/ecb09b07a4e9856a561252d380eb6294d ...

  7. (链表 双指针) leetcode 19. Remove Nth Node From End of List

    Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...

  8. bzoj1040 基环树森林dp

    https://www.lydsy.com/JudgeOnline/problem.php?id=1040 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社 ...

  9. IMDB影评倾向分类 - N-Gram

    catalogue . 数据集 . 模型设计 . 训练 1. 数据集 0x1: IMDB影评数据 本数据库含有来自IMDB的25,000条影评,被标记为正面/负面两种评价 from keras.dat ...

  10. python 列表 元祖 集合

    #####################概念#######################1,什么是列表: 列表由[]表示,里面每一项元素用逗号隔开,里面什么都可以装.能装对象的对象. 列表可以装大 ...