ASP.NET配置Ueditor编辑器上传图片路径

一、配置ueditor/editor_config.js文件,将javascript

        //图片上传配置区
        ,imageUrl:URL+"net/imageUp.ashx"             //图片上传提交地址
        ,imagePath:URL + "net/"                     //图片修正地址,引用了fixedImagePath,若有特殊需求,可自行配置

修改成html

        //图片上传配置区
        ,imageUrl:URL+"net/imageUp.ashx"             //图片上传提交地址
        ,imagePath:"http://localhost:3499/"                     //图片修正地址,引用了fixedImagePath,若有特殊需求,可自行配置

说明:其实,这里惟一变的地方就是imagePath,由于URL的值是经过一个函数计算出来的,其默认是就是ueditor所在的网页路径,好比:http://www.a.com/ueditor/。若是imagePath不作修改的话,那么咱们在上传完图片,点击肯定以后,编辑器返回的图片路径就是http://www.a.com/ueditor/net/upload/xxxxx.jpg。可是咱们不想保存在/ueditor/net/upload/目录下,咱们只想保存在根目录下面的upload下面,怎么办?那咱们只要修改imagePath的值就能够了。就像上面同样。java

二、修改ueditor/net/imageUp.ashx文件,将文件头部的网络

<%@ Assembly Src="Uploader.cs" %>

去掉。若是不去掉,就会提示:网络连接错误,请检查配置后重试。在网上查了下缘由,说是跟.NET Framework版本有关。个人是4.0的。编辑器

三、修改ueditor/net/Uploader.cs文件,将函数

        pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
        uploadpath = cxt.Server.MapPath(pathbase);//获取文件上传路径

修改成网站

        pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
        uploadpath = cxt.Server.MapPath("~/" + pathbase);//获取文件上传路径

说明:由于这里的pathbase的值是“upload/”,咱们获取文件上传路径的值就是:http://www.a.com/ueditor/net/upload/,不是咱们想要的结果,因此我在这里加了个定位到网站根目录的字符串。这样uploadpath返回的值就是正确的了:http://www.a.com/upload/。ui

四、在页面上添加代码,显示ueditor。spa

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ueditor.aspx.cs" Inherits="WebForm.Ueditor" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="ueditor/ueditor.all.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script id="myEditor" type="text/plain" name="content"></script>
    </div>
    </form>
</body>
</html>
<script type="text/javascript">
    //建立编辑器
    var editor = new UE.ui.Editor({ initialFrameWidth: 600, initialFrameHeight: 300 }); editor.render("myEditor"); </script>

仅供参考。调试

其实,咱们只要调试下就能够解决上传路径的问题。很简单的。

相关文章
相关标签/搜索