1.页面

//html
<textarea id="txtContent" name="editor1"></textarea>

//js
<script src="../../Scripts/kindeditor/kindeditor.js" type="text/javascript"></script>

var editor1;
        $(function () {
            KindEditor.ready(function (KE) {
                editor1 = KE.create('textarea[name="editor1"]',
                {
                    resizeType: 0,
                    allowImageRemote: false,
                    imageUploadLimit: 10,  //批量上传最多10张
                    uploadJson: '/Information/UpContentFile'
                });
            });
    }

2.后台

//Infomation/UpContentFile      
        /// <summary>
        /// 上传内容附件、图片
        /// </summary>
        /// <returns></returns>
        [LoginAuth(IsAuth = true)]
        public JsonResult UpContentFile()
        {
            var hash = UpContentFile(Request.Files, "upload/information_content/");  //上传文件夹   //UpContentFile函数在下↓↓↓
return Json(hash, "text/html;charset=UTF-8"); } 

3.基础函数

        /// <summary>
        /// 上传内容附件、图片
        /// </summary>
        /// <returns></returns>
        protected Hashtable UpContentFile(HttpFileCollectionBase files, string path)
        {
            int maxSize = 2048000;  //图片限制大小
            string fileTypes = "gif,jpg,jpeg,png,bmp";  //限制格式
            Hashtable hash = new Hashtable();
            if (files.Count <= 0)
            {
                hash = new Hashtable();
                hash["error"] = 1;
                hash["message"] = "请选择文件";
                return hash;
            }

            string fileName = files[0].FileName;
            string fileExt = Path.GetExtension(fileName).ToLower();
            if (files[0].InputStream == null || files[0].InputStream.Length > maxSize)
            {
                hash = new Hashtable();
                hash["error"] = 1;
                hash["message"] = "上传文件大小超过限制";
                return hash;
            }

            if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                hash = new Hashtable();
                hash["error"] = 1;
                hash["message"] = "上传文件格式错误(只支持:[gif,jpg,jpeg,png,bmp]格式)";
                return hash;
            }

            var fileurl = string.Empty;
            fileurl = string.Format("../{0}", UpFile(files[0], path));
            if (!string.IsNullOrEmpty(fileurl))
            {
                hash = new Hashtable();
                hash["error"] = 0;
                hash["url"] = fileurl;
                return hash;
            }
            return null;
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <param name="path"></param>
        /// <param name="filename">文件名</param>
        /// <param name="fix">后缀名</param>
        /// <returns></returns>
        protected string UpFile(HttpPostedFileBase file, string path, string filename = "", string fix = "")
        {
            try
            {
                string mpath = Server.MapPath("/");
                var a = Directory.Exists(mpath + path);
                var b = mpath + path;
                if (Directory.Exists(mpath + path) == false)//判断文件夹是否存在
                    Directory.CreateDirectory(mpath + path);//创建文件夹

                if (string.IsNullOrEmpty(filename))
                {
                    filename = Tools.GenerateTimeStamp(DateTime.Now);
                }
                if (string.IsNullOrEmpty(fix))
                {
                    fix = System.IO.Path.GetExtension(file.FileName);
                }
                string imgpath = path + string.Format("{0}{1}", filename, fix);
                file.SaveAs(mpath + imgpath);
                return imgpath;
            }
            catch (Exception e)
            {
                ErrorLog.RecordErrorLog(e);
                return "";
            }
        }

4. 提示框添加提示(效果如图)

    or

修改 :  \Scripts\kindeditor\plugins\image\image.js

var html = [

…………
 //local upload - start
            '<div class="tab2" style="display:none;">',
            '<iframe name="' + target + '" style="display:none;"></iframe>',
            '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
       //不超过2M
            '<div class="ke-dialog-row">',
            '<span>注:上传文件大小不超过2M</span>',
            '</div>',
        //file
            '<div class="ke-dialog-row">',
            hiddenElements.join(''),
…………
]

 

修改 :\Scripts\kindeditor\kindeditor-all.js

KindEditor.lang({
…………
'multiimage.uploadDesc': '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
…………
})

 

 

5.修改默认字体(9px 10px……32px )

修改 :\Scripts\kindeditor\kindeditor-all.js  等

Scripts\kindeditor\kindeditor-all.js(274)    fontSizeTable: ['24px', '32px', '34px', '36px', '38px', '40px', '42px'],   【ctrl+F 查找fontSizeTable】
Scripts\kindeditor\kindeditor.js(274):
Scripts\kindeditor\src\config.js(61)

 

 

6.

7.

posted on 2016-12-20 10:30  Nyah  阅读(161)  评论(0)    收藏  举报