1、配置ueditor/editor_config.js文件,將
//圖片上傳配置區 ,imageUrl:URL+"net/imageUp.ashx" //圖片上傳提交地址 ,imagePath:URL + "net/" //圖片修正地址,引用了fixedImagePath,如有特殊需求,可自行配置
修改為
//圖片上傳配置區 ,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的值就可以了。就像上面一樣。
2、修改ueditor/net/imageUp.ashx文件,將文件頭部的
<%@ Assembly Src="Uploader.cs" %>
去掉。如果不去掉,就會提示:網絡鏈接錯誤,請檢查配置后重試。在網上查了下原因,說是跟.NET Framework版本有關。我的是4.0的。
3、修改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/。
4、在頁面上添加代碼,顯示ueditor。
<%@ 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>
僅供參考。
其實,我們只要調試下就可以解決上傳路徑的問題。很簡單的。