FCKeditor編輯器添加圖片上傳功能及圖片路徑問題解決方法

現(xiàn)在很多CMS系統(tǒng)因為安全原因會把后臺編輯器里的上傳功能給去除,但這樣一來對實際使用過程造成了很多麻煩,今天我們以ASPCMS系統(tǒng)的FCKeditor編輯器為例,說明一下如何增加圖片上傳功能。
1. 打開網(wǎng)站后臺編輯器里的admin/editor/fckconfig.js這個文件
找到FCKConfig.ImageUpload = false 這句,把false改成true就行啦。
FCKConfig.ImageBrowser = false ; 這里也同樣把false改成true
2. 看一下admin/editor/editor目錄下面的filemanager文件夾是否存在,如果不在就去下載一個2.6.3版本以上的fck編輯器,把里面的filemanager文件夾復(fù)制過來。當(dāng)然這里是ASP的,所以其他語言像PHP什么的文件夾可以刪除。
3. 接下來設(shè)置文件上傳的路徑,打開admin/editor/filemanager/connectors/asp文件夾的config.asp這個文件進(jìn)行如下設(shè)置
ConfigIsEnabled = True 是否開啟上傳功能
ConfigUserFilesPath = “../../../../../uploads/” 文件上傳目錄,相對于該文件夾
這里要重點指出的ConfigUserFilesPath = “../../../../../uploads/”這里如果這樣設(shè)置,我最后發(fā)現(xiàn)兩個問題

A. ConfigUserFilesPath = “../../../../../uploads/”這樣設(shè)置雖然圖片可以上傳,但插入編輯器里的圖片路徑是有問題的,所以我試了很多次最后把它改成ConfigUserFilesPath = “/uploads/”就可以了。如果您的網(wǎng)站是放在下級文件夾里也可以這樣設(shè)置ConfigUserFilesPath = “文件夾名稱/uploads/”。
B. 至于第二個問題,我感覺好奇怪,F(xiàn)CKeditor編輯器的圖片路徑會出現(xiàn)兩個斜杠//,雖然圖片也能顯示,但看起來總歸不舒服。請打開admin/editor/editor/ filemanager/connectors/asp文件夾里的,io.asp這個文件,請把:
function CombinePaths( sBasePath, sFolder)
CombinePaths = RemoveFromEnd(sBasePath, "/") & "/" & RemoveFromStart( sFolder, "/")
end function
改成
function CombinePaths( sBasePath, sFolder)
sFolder = replace(sFolder, "", "/")
CombinePaths = RemoveFromEnd(sBasePath, "/") & "/" & RemoveFromStart( sFolder, "/")
end function
4. 最后設(shè)置上傳后的圖片自動改名,請打開admin/editor/editor/ filemanager/connectors/asp文件夾里的commands.asp這個文件
在文件中添加如下語句
dim rannum
dim dtnow
dim getnewfilename
dtnow=now()
randomize
rannum=int(90*rnd)+10
getnewfilename=year(dtnow) & right("0" & month(dtnow),2) & right("0" & day(dtnow),2) & right("0"& hour(dtnow),2) & right("0”"& minute(dtnow),2) & right("0" & second(dtnow),2) & rannum
并將
sFileName = ouploader.file("newfile")name
改為
sFileName = getnewfilename &"."& split(ouploader.file("newfile").name,".")(1)
以上是關(guān)于ASPCMS網(wǎng)站系統(tǒng)的一點小小的改進(jìn),希望對有這方面需要的朋友有所幫助,今后我們還將關(guān)注該系統(tǒng)的其他問題。
用正則表達(dá)式解決FCKEditor圖片路徑問題
在用FCKEditor發(fā)郵件時,正文中圖片會顯示不出來,因為它默認(rèn)路徑是userfiles/images/*.jpg,如下
<input type="image" height="131" width="139"
src="/userfiles/image/_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
怎么轉(zhuǎn)換為:
<input type="image" height="131" width="139" src="\\[Server]\userfiles\image\_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
asp解法:
'郵件正文
strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
set rs=connection.execute(strsql)
myTxt = rs("txt")
'利用正則表達(dá)式替換img標(biāo)記
dim objRe
set objRe = New RegExp
'設(shè)定正則式
objRe.Pattern = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?"
objRe.IgnoreCase = true
objRe.Multiline = true
objRe.Global = true
set matches = objRe.Execute(myTxt)
newtxt = myTxt
for each match in matches
cccc = split(match.value,"/")
if(ubound(cccc) <> 0) then
'獲得應(yīng)該的字符串
for i=0 to ubound(cccc)
if i = 0 then
mystr = cccc(0)&"\\[server]\"
else if i= ubound(cccc) then
mystr = mystr&cccc(i)
else
mystr = mystr&cccc(i)&"\"
end if
end if
next
newtxt = Replace(newtxt,match.value,mystr)
end if
next
set objRE = nothing
a = "<body background='\\[server]\2008back.gif'>"
Body=a& newtxt &"</body>"
.Net 解法:
using System.Text.RegularExpressions;
string convertExp(string strTxt)
{
string strPattern = "(src=)('|" + (char)34 + "| )?(.[^'| |" + (char)34 + "]*)(\\.)(jpg|gif|png|bmp|jpeg)('|" + (char)34 + "| |>)?";
// Compile the regular expression.
Regex objRe=new Regex(strPattern);
// Match the regular expression pattern against a text string.
MatchCollection matches=objRe.Matches(strTxt);
string mystr="";
string strNewTxt = strTxt;
foreach (Match match in matches)
{
string[] strC = match.Value.Split('/');
//if it's the bottom jpg,break Foreach
if (strC[strC.Length - 1].ToString() == "asdf.jpg\"")
{
break;
}
if (strC.Length != 0)
{
for (int i = 0; i < strC.Length; i++)
{
if (i == 0)
mystr = strC[0] + "\\\\[server]\\";
else if (i == strC.Length - 1)
mystr = mystr + strC[i];
else
mystr = mystr + strC[i] + "\\";
}
strNewTxt = strNewTxt.Replace(match.Value, mystr);
}
}
return strNewTxt;
}
調(diào)用:
StringBuilder sb = getMailContent(strSubject);
lblPreview.Text = convertExp(sb.ToString());
到此這篇關(guān)于FCKeditor編輯器添加圖片上傳功能及圖片路徑問題解決方法的文章就介紹到這了,更多相關(guān)FCKeditor 圖片上傳內(nèi)容請搜素腳本之家以前的文章或下面相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
fckeditor在ie9中無法彈出對話框的解決方法(彈出層兼容問題)
升級到 IE 9后,fckeditor在IE 9里的彈出浮動層會出現(xiàn)bug,里面的內(nèi)容不會出現(xiàn)2012-04-04
在kindEditor中獲取當(dāng)前光標(biāo)的位置索引的實現(xiàn)代碼
一直在用KindEditor,今天要用到光標(biāo)的位置,然后就gg一下辦法,后來發(fā)現(xiàn)這東西的編輯區(qū)域居然是iframe里面的一個body,不是textarea/input,后來就翻開了他的代碼看,發(fā)現(xiàn)有個insertHtml2011-11-11
KindEditor 4.x 在線編輯器常用方法小結(jié)
要修改默認(rèn)后臺程序處理文件,修改plugins(插件文件夾)下的JavaScript內(nèi)容fileManagerJson改為自己使用程序語言2011-11-11
針對PHP環(huán)境下Fckeditor編輯器上傳圖片配置詳細(xì)教程
今天介紹Fckeditor上傳圖片功能在PHP中的配置方法,涉及Fckeditor上傳圖片的上傳路徑配置、限制Fckeditor上傳圖片大小設(shè)置、Fckeditor上傳圖片文件名重名及亂碼解決方法以及針對上傳圖片添加水印功能的實現(xiàn)方法,只要掌握了以上四點,F(xiàn)ckeditor在大部分PHP類型網(wǎng)站中的應(yīng)用都能解決2014-04-04
Fckeditor XML Request error:internal server error (500) 解決方法
本文章收藏了關(guān)于FCKEditor XML Request Error:Internal Server Error(500)各種問題的解決辦法2012-09-09

