FCKeditor在web.config中有多項設置:view plaincopy to clipboardPRint?
<appSettings>
<!--FCKeditor設置(主要是以下兩項)-->
<!--FCKeditor編輯器路徑-->
<add key="FCKeditor:BasePath" value="/FCKeditor/"/>
<!--FCKeditor用戶附件上傳路徑-->
<add key="FCKeditor:UserFilesPath" value="/Resources/TempUpload/"/>
</appSettings>
<appSettings>
<!--FCKeditor設置(主要是以下兩項)-->
<!--FCKeditor編輯器路徑-->
<add key="FCKeditor:BasePath" value="/FCKeditor/"/>
<!--FCKeditor用戶附件上傳路徑-->
<add key="FCKeditor:UserFilesPath" value="/Resources/TempUpload/"/>
</appSettings> 用戶登錄后通過FCKeditor上傳文件則要放置在用戶共用上傳路徑“/Resources/UserUpload/”+“用戶郵箱地址”,如“/Resources/UserUpload/user@Gmail.com”。FCKeditor.net獲取上傳路徑文件是:FileWorkerBase.cs,打開找到以下部分view plaincopy to clipboardprint?
protected string UserFilesPath
{
get
{
if ( sUserFilesPath == null )
{
// 第一回從application["FCKeditor:UserFilesPath"] 中讀取,如果沒有嘗試其它方式
sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;
// 第二回從session["FCKeditor:UserFilesPath"] 中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;
// 第三回從web.config中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;
// 第四回從DEFAULT_USER_FILES_PATH(這個變量在同文件中)中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
sUserFilesPath = DEFAULT_USER_FILES_PATH ;
// 第五回從網址參數ServerPath中讀取
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = Request.QueryString["ServerPath"] ;
}
}
}
// Check that the user path ends with slash ("/")
if ( ! sUserFilesPath.EndsWith("/") )
sUserFilesPath += "/" ;
}
return sUserFilesPath ;
}
}
protected string UserFilesPath
{
get
{
if ( sUserFilesPath == null )
{
// 第一回從Application["FCKeditor:UserFilesPath"] 中讀取,如果沒有嘗試其它方式
sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;
// 第二回從Session["FCKeditor:UserFilesPath"] 中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;
// 第三回從web.config中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;
// 第四回從DEFAULT_USER_FILES_PATH(這個變量在同文件中)中讀取,如果沒有嘗試其它方式
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
sUserFilesPath = DEFAULT_USER_FILES_PATH ;
// 第五回從網址參數ServerPath中讀取
if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
{
sUserFilesPath = Request.QueryString["ServerPath"] ;
}
}
}
// Check that the user path ends with slash ("/")
if ( ! sUserFilesPath.EndsWith("/") )
sUserFilesPath += "/" ;
}
return sUserFilesPath ;
}
} 從上面的注釋可以看到用戶上傳路徑的順序,只要在頁面加載的時候設置下Session["FCKeditor:UserFilesPath"]就可以設置FCKeditor上用戶上傳路徑了view plaincopy to clipboardprint?
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Session["FCKeditor:UserFilesPath"] = "用戶上傳路徑";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Session["FCKeditor:UserFilesPath"] = "用戶上傳路徑";
} (我在配置的時候關閉了文件瀏覽,只提供文件快速上傳)但是在使用的時候如果“Resources/UserUpload/[email protected]”中的[email protected]路徑沒創建,上傳中FCKeditor它不會創建,也導致了文件無法上傳成功,那就需要再修改FCKeditor.net項目中的Uploader.cs文件,添加一段文件夾存在的檢測代碼,如果不存在用戶指定的文件夾側創建一個view plaincopy to clipboardprint?
// Get the uploaded file name.
string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ;
int iCounter = 0 ;
//景裔添加
//檢查上傳目錄是否已經被創建
//開始==========================================
//檢查當前完整路徑是否存在,不存在則開始逐級輪詢檢查,不存則就創建
if (!System.IO.Directory.Exists(UserFilesDirectory))
{
string[] tempDirectorys = UserFilesDirectory.Split(new string[] { "http://" }, StringSplitOptions.RemoveEmptyEntries);
string tempDirectory = string.Empty;
for (int i = 0; i < tempDirectorys.Length; i++)
{
tempDirectory += tempDirectorys[i] + "http://";
if (!System.IO.Directory.Exists(tempDirectory))
System.IO.Directory.CreateDirectory(tempDirectory);
}
}
//結束==========================================
while ( true )
{
string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;
if ( System.IO.File.Exists( sFilePath ) )
{
iCounter++ ;
sFileName =
System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +
"(" + iCounter + ")" +
System.IO.Path.GetExtension( oFile.FileName ) ;
iErrorNumber = 201 ;
}
else
{
oFile.SaveAs( sFilePath ) ;
sFileUrl = this.UserFilesPath + sFileName ;
break ;
}
}
// Get the uploaded file name.
string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ;
int iCounter = 0 ;
//景裔添加
//檢查上傳目錄是否已經被創建
//開始==========================================
//檢查當前完整路徑是否存在,不存在則開始逐級輪詢檢查,不存則就創建
if (!System.IO.Directory.Exists(UserFilesDirectory))
{
string[] tempDirectorys = UserFilesDirectory.Split(new string[] { "http://" }, StringSplitOptions.RemoveEmptyEntries);
string tempDirectory = string.Empty;
for (int i = 0; i < tempDirectorys.Length; i++)
{
tempDirectory += tempDirectorys[i] + "http://";
if (!System.IO.Directory.Exists(tempDirectory))
System.IO.Directory.CreateDirectory(tempDirectory);
}
}
//結束==========================================
while ( true )
{
string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;
if ( System.IO.File.Exists( sFilePath ) )
{
iCounter++ ;
sFileName =
System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +
"(" + iCounter + ")" +
System.IO.Path.GetExtension( oFile.FileName ) ;
iErrorNumber = 201 ;
}
else
{
oFile.SaveAs( sFilePath ) ;
sFileUrl = this.UserFilesPath + sFileName ;
break ;
}
} 這樣就基本解決了多用戶分文件夾上傳圖片的問題,不過也有缺陷的地方,就是當用戶Session超時的時候,用戶再使用瀏覽器上傳文件就不會按照指定用戶文件夾上傳來了,分析這個情況可以得出:這個時候用戶通過編輯器上傳的文件也就是對編輯器內容作出了修改,但是因為Session超時了,所以可以把做出的修改視作無效,既然修改無效,那用戶上傳的文件也是沒用的,所在我在web.config中又設置了個默認文件上傳位置,所有無效文件都會上傳到這里,那個回清理的時候也方便多了 不知道哪位大蝦還有更好的辦法。
出處:http://blog.breakn.net/article.asp?id=388
新聞熱點
疑難解答