百度编辑器UEditor1.1.8.1最新版使用之--[.NET版图片上传]

ueditor编辑器放在项目根目录,目录名为ueditor

先配置editor_config.js

14imagePath:URL + "",

51-66

 iframeUrlMap:{
'anchor':'~/ueditor/dialogs/anchor/anchor.html',
'insertimage': '~/ueditor/dialogs/image/image.html',
'inserttable': '~/ueditor/dialogs/table/table.html',
'link': '~/ueditor/dialogs/link/link.html',
'spechars': '~/ueditor/dialogs/spechars/spechars.html',
'searchreplace': '~/ueditor/dialogs/searchreplace/searchreplace.html',
'map': '~/ueditor/dialogs/map/map.html',
'gmap': '~/ueditor/dialogs/gmap/gmap.html',
'insertvideo': '~/ueditor/dialogs/video/video.html',
'help': '~/ueditor/dialogs/help/help.html',
'highlightcode': '~/ueditor/dialogs/code/code.html',
'emotion': '~/ueditor/dialogs/emotion/emotion.html',
'wordimage': '~/ueditor/dialogs/wordimage/wordimage.html',
'insertframe': '~/ueditor/dialogs/insertframe/insertframe.html'
},

260行 图片背景

'.anchorclass{background: url("' + URL + 'ueditor/themes/default/images/anchor.gif") ...

299230

highlightJsUrl:URL + "ueditor/third-party/SyntaxHighlighter/shCore.js",
highlightCssUrl:URL + "ueditor/third-party/SyntaxHighlighter/shCoreDefault.css",
--------------------JS配置修改完毕---------------------

 

ueditor/server/upload/net/文件夹下建立一般处理文件upload.ashx

修改ueditor/dialogs/image/image.html304url: '../../server/upload/net/upload.ashx',

Upload.ashx内容如下

 

<%@ WebHandler Language="C#" Class="upload" %>

using System;
using System.Web;
using System.IO;

public class upload : IHttpHandler
{
    /// <summary>
    /// 配置
    /// </summary>
    public struct Config
    {
        /// <summary>上传保存路径</summary>
        public string UploadPath;
        /// <summary>允许的单个文件大小,单位为KB</summary>
        public int PicSize;
        /// <summary>允许的图片格式</summary>
        public string PicType;
    }
    public void ProcessRequest(HttpContext context)
    {
        Config cfg = new Config();
        cfg.UploadPath = "UploadFiles/" + DateTime.Now.ToString("yyyy/MM/dd/"); ;
        cfg.PicSize = 2048;
        cfg.PicType = ".jpg,.gif,.png,.bmp";
        
        //文件上传状态,当成功时返回SUCCESS,其余值将直接返回对应字符窜并显示在图片预览框,同时可以在前端页面通过回调函数获取对应字符窜
        string state = "SUCCESS";
        string _upPath = context.Server.MapPath("~/" + cfg.UploadPath);
        string _returnPath = String.Empty;//返回路径
        string _picTitle = context.Request.Form["pictitle"].ToString();//获取图片名称
        HttpPostedFile _oFile = context.Request.Files["picdata"];//获取图片信息
        string _fileExt = Path.GetExtension(_oFile.FileName).ToLower();//文件扩展名
        
        if (cfg.PicSize * 1024 <= _oFile.ContentLength)//判断图片大小
            state = "图片超过最大大小";

        string[] picTypeArr = cfg.PicType.Split(',');//获取图片类型
        if (Array.IndexOf(picTypeArr, _fileExt) < 0)//判断图片格式
            state = "不允许上传该类型图片";

        if (state == "SUCCESS")
        {
            Guid guid = Guid.NewGuid();            
            string filename = guid.ToString() + _fileExt;//文件名称
            try
            {
                if (!Directory.Exists(_upPath))
                    Directory.CreateDirectory(_upPath);
                _oFile.SaveAs(_upPath + filename);//保存附件  
                _returnPath =cfg.UploadPath+ filename;
            }
            catch
            {
                state = "ERROR";
            }
        }
        context.Response.ContentType = "text/Xml";
        context.Response.AppendHeader("Cache-Control", "no-cache");
        context.Response.Write("{'url':'" + _returnPath + "','title':'" + _picTitle + "','state':'" + state + "'}");
        context.Response.End();
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

上一篇‡: 一些SQL语句(备忘)

下一篇‡: 迅雷,快车,旋风链接编码解码 C#

最近回复