欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

xheditor开源编辑器ajax上传功能的完善

发布时间:2025/4/16 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 xheditor开源编辑器ajax上传功能的完善 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

编辑器很多大家肯定都不陌生,有名的fckeditor,ewebeditor...
这年头倒霉的事都轮到我了,前不久我用aspx写了个网站,也是帮学校写的,关键是网络办老师郁闷,由于我用的是fckeditor,可是他非说这个东西有漏洞,于是我去网上找了些资料,哪个编辑器没漏洞啊,我对老师无语啊,可能前不久我们学校网站被黑,老师慌了,他就是不让我上传...于是我就寻思着换个编辑器,那就搞个无名的,开源的,找来找去找到了xheditor,这个编辑器确实也可以,调用方便,不用改代码很多,在aspx下就OK搞定,但这种开源的东西功能上肯定不过关啊,其中一个就是上传,也就这个东西最关键。
官网上的最新版本就有一个php的开发版本(支持ajax上传的),现在我要做的就是:对xheditor写个在aspx下上传的功能
xheditor的下载地址:http://code.google.com/p/xheditor/downloads/list

下面是编辑器的界面:

upload.aspx页面代码:

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class admin_Upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        FileUpload.FileUpLoad fp = new FileUpload.FileUpLoad();
        fp.FilePath = "upload";

        Response.Write(fp.uploadFile(Request.Files["upload"]));
    }
}

 

 

FileUpload.cs:

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

/// <summary>
///FileUpload 的摘要说明
/// </summary>
public class FileUpload
{
    public class FileUpLoad
    {
        private string fileExtension;


        /// <summary>
        /// 上传文件路径
        /// </summary>
        public string FilePath
        {
            get
            {
                return filepath;
            }
            set
            {
                filepath = value;
            }
        }
        private string filepath;


        public string uploadFile(HttpPostedFile postedFile)
        {

            string fileName = Path.GetFileName(postedFile.FileName);
            string fileExtension = Path.GetExtension(postedFile.FileName);
            string phyPath = HttpContext.Current.Request.MapPath(FilePath);

            DirectoryInfo upDir = new DirectoryInfo(phyPath);
            //判断上传路径是否存在,不存在则创建
            if (!upDir.Exists)
            {
                upDir.Create();
            }
            //保存文件
            try
            {
                postedFile.SaveAs(phyPath + "\\" + fileName);
                return "{err:\"\",msg:\"../" + FilePath + "/" + fileName + "\"}";
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }

        }
    }
}

希望广大的高手继续更新完善...把这个接口做得更好!

 

转载于:https://www.cnblogs.com/zhulidong/archive/2009/11/01/1593880.html

总结

以上是生活随笔为你收集整理的xheditor开源编辑器ajax上传功能的完善的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。