FCKeditor(現已更名為 CKEditor)曾是經典的 Web 富文本編輯器。本文記錄其安裝、精簡、配置與整合流程,供維護舊專案參考。
刪除不必要檔案以節省空間:
_ 開頭的目錄:_samples、_testcases.asp、.jsp、.cfm、.lasso、.pl 等php 相關連接器與核心檔案fckconfig.js// 語言與介面
FCKConfig.AutoDetectLanguage = true; // 自動偵測語言
FCKConfig.DefaultLanguage = 'zh-tw'; // 繁體中文介面
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/';
FCKConfig.ToolbarStartExpanded = true; // 預設展開工具列
// 字體設定(加入中文字體)
FCKConfig.FontNames = '新細明體;微軟正黑體;標楷體;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana';
// 編輯區預設樣式(修改 fck_editorarea.css)
/* body, td { font-family: '微軟正黑體', Arial, sans-serif; font-size: 14px; } */
var _FileBrowserLanguage = 'php';
var _QuickUploadLanguage = 'php';
editor/filemanager/browser/default/connectors/php/config.php$Config['Enabled'] = true;
$Config['UserFilesPath'] = '/UserFiles/'; // 公開可存取的 URL 路徑
$Config['UserFilesAbsolutePath'] = '/var/www/html/UserFiles/'; // 伺服器實體路徑
editor/filemanager/upload/php/config.php$Config['Enabled'] = true;
$Config['UseFileType'] = true;
$Config['UserFilesPath'] = '/UserFiles/'; // 必須與瀏覽器設定一致
$Config['UserFilesAbsolutePath'] = '/var/www/html/UserFiles/';
注意: UserFiles 目錄需具備 Web 伺服器寫入權限(chmod 755 或 777 視環境而定)。
<?php
require_once('fckeditor/fckeditor.php');
$oFCKeditor = new FCKeditor('editor_content');
$oFCKeditor->BasePath = '/fckeditor/'; // 必須與實際路徑一致,否則找不到 fckeditor.html
$oFCKeditor->Value = ''; // 預設內容
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '400';
$oFCKeditor->Create();
?>
<?php
// 接收資料(建議配合 prepared statement 防 SQL 注入)
$content = $_POST['editor_content'] ?? '';
// 存入資料庫前處理
$safe_content = addslashes($content); // 或使用 mysqli_real_escape_string / PDO
// 讀出顯示時還原
echo stripslashes($safe_content);
說明: addslashes() 會在單引號、雙引號、反斜線、NULL 前加上反斜線;stripslashes() 為反向操作。現代開發建議改用 PDO Prepared Statements 自動處理跳脫,避免手動管理。
FCKeditor 已停止維護,新專案強烈建議直接使用 CKEditor 4/5、TinyMCE 或 Quill 等現代編輯器,支援更好、安全性更高、功能更豐富。