FCKeditor (後更名為 CKEditor 3+) 為經典富文本編輯器。本文針對 FCKeditor 2.6.x 版本在 Classic ASP 環境的完整部署與客製化。
// 語言:關閉自動偵測,強制繁體中文 (或 zh-cn 簡體)
FCKConfig.AutoDetectLanguage = false;
FCKConfig.DefaultLanguage = 'zh-tw';
// 字型清單:加入中文字型
FCKConfig.FontNames = '新細明體;標楷體;微軟正黑體;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana';
// 啟用/關閉瀏覽與上傳功能
FCKConfig.LinkBrowser = true;
FCKConfig.ImageBrowser = true;
FCKConfig.FlashBrowser = true;
FCKConfig.LinkUpload = true;
FCKConfig.ImageUpload = true;
FCKConfig.FlashUpload = true;
// 修正 QuickUploadLanguage Bug (原版變數名稱錯誤)
FCKConfig.QuickUploadLanguage = 'asp'; // 原為 FCKConfig.QuickUploadLanguage (未定義)
FCKConfig.QuickUploadPath = '/asp/upload.asp'; // 依實際路徑調整
ConfigIsEnabled = True
ConfigUserFilesPath = "/uploads/" ' 虛擬路徑 (網站根目錄下)
ConfigUserFilesAbsolutePath = Server.MapPath("/uploads/") ' 實體路徑 (需寫入權限)
' 允許上傳副檔名
ConfigAllowedExtensions = Array("jpg","jpeg","png","gif","pdf","doc","docx","xls","xlsx","zip","rar")
ConfigDeniedExtensions = Array("asp","asa","aspx","php","jsp","exe","dll","bat","cmd","sh")
ConfigIsEnabled = True
ConfigUserFilesPath = "/uploads/"
ConfigUserFilesAbsolutePath = Server.MapPath("/uploads/")
ConfigAllowedExtensions = Array("jpg","jpeg","png","gif","pdf","doc","docx","xls","xlsx","zip","rar")
ConfigDeniedExtensions = Array("asp","asa","aspx","php","jsp","exe","dll","bat","cmd","sh")
' 在 FileUpload 函式中,取得檔名後插入:
sFileName = GetSafeFileName(sFileName)
Function GetSafeFileName(originalName)
Dim ext, base, stamp, rnd
ext = LCase(Mid(originalName, InStrRev(originalName, ".") + 1))
base = Left(originalName, InStrRev(originalName, ".") - 1)
stamp = Year(Now) & Right("0"&Month(Now),2) & Right("0"&Day(Now),2) & _
Right("0"&Hour(Now),2) & Right("0"&Minute(Now),2) & Right("0"&Second(Now),2)
Randomize: rnd = Int(900*Rnd) + 100
GetSafeFileName = stamp & "_" & rnd & "." & ext
End Function
' 同樣在取得 oUploader.File("NewFile").Name 後:
sFileName = GetSafeFileName(oUploader.File("NewFile").Name)
<!--#include virtual="/FCKeditor/fckeditor.asp"-->
<%
Dim oFCK
Set oFCK = New FCKeditor
oFCK.BasePath = "/FCKeditor/"
oFCK.ToolbarSet = "Basic" ' 或 "Default", "Custom"
oFCK.Width = "100%"
oFCK.Height = 400
oFCK.Value = Server.HTMLEncode(existingContent) ' 既有內容
oFCK.Create "content" ' 產生名為 content 的隱藏 input
%>
<form method="post" action="save.asp">
<%=oFCK.CreateHtml()%> ' 或直接用上面的 oFCK.Create "content"
<input type="submit" value="送出">
</form>
<%
Dim content
content = Request.Form("content")
' 必做:XSS 過濾 (伺服端二次防禦)
' 可用 ASPHTMLSanitizer 或自行 Regex 白名單
content = SanitizeHTML(content) ' 自行實作或引用庫
' 存入資料庫 (參數化)
Dim cmd: Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "UPDATE Articles SET Content=? WHERE ID=?"
cmd.Parameters.Append cmd.CreateParameter("@c", 201, 1, , content) ' adLongVarChar
cmd.Parameters.Append cmd.CreateParameter("@id", 3, 1, , articleId) ' adInteger
cmd.Execute
Response.Redirect "list.asp"
%>