首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

PHP 環境下 FCKeditor 2.4.2 精簡配置與中文化完整指南

     編輯:PHP 綜合知識

前言

FCKeditor(現 CKEditor 前身)支援多語言、多平台。本文針對 PHP 環境,說明如何精簡檔案、配置中文介面、字體與上傳路徑。

一、精簡檔案結構(刪除冗餘)

  1. 根目錄:刪除所有以 _ 開頭的暫存檔/資料夾。保留:fckconfig.js、fckeditor.js、fckeditor.php、fckeditor_php4.php、fckeditor_php5.php、fckstyles.xml、fcktemplates.xml、editor/ 資料夾。
  2. editor/lang/:僅保留 en.js、zh-cn.js(簡中)、zh-tw.js(繁中)。
  3. editor/skins/:依需求保留 default(輕量)、office2003、silver。
  4. editor/filemanager/browser/default/connectors/:僅保留 php/。
  5. editor/filemanager/upload/:同理,僅保留 php/。

二、基本配置

1. 預設語言(fckconfig.js 第 56-57 行)

FCKConfig.AutoDetectLanguage = false; // 關閉自動偵測
FCKConfig.DefaultLanguage = 'zh-cn';  // 設為簡體中文

2. 字體列表(第 142 行)

FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;' +
    '宋體;楷體_GB2312;新宋體;黑體;隸書;幼圓;'; // 依需求增減

3. 工具列配置(依角色簡化)

FCKConfig.ToolbarSets["Basic"] = [
    ['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
    '/',
    ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
    ['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Style','FontFormat','FontName','FontSize'],
    ['TextColor','BGColor'],
    ['FitWindow','ShowBlocks','-','About']
];

三、檔案上傳配置(重點)

1. PHP 連接器配置

編輯 editor/filemanager/browser/default/connectors/php/config.php:

$Config['Enabled'] = true;
$Config['UserFilesPath'] = '/UserFiles/'; // URL 路徑
$Config['UserFilesAbsolutePath'] = '/var/www/html/UserFiles/'; // 絕對路徑,需可寫

// 允許上傳類型
$Config['AllowedExtensions']['File'] = array('7z','aiff','asf','avi','bmp','csv','doc','fla','flv','gif','gz','gzip','jpeg','jpg','mid','mov','mp3','mp4','mpc','mpeg','mpg','ods','odt','pdf','png','ppt','pxd','qt','ram','rar','rm','rmi','rmvb','rtf','sdc','sitd','swf','sxc','sxw','tar','tgz','tif','tiff','txt','vsd','wav','wma','wmv','xls','xlsx','zip');
$Config['DeniedExtensions']['File'] = array();

// 圖片上傳
$Config['AllowedExtensions']['Image'] = array('bmp','gif','jpeg','jpg','png');
$Config['DeniedExtensions']['Image'] = array();

// 快取設定
$Config['QuickUploadPath']['Image'] = $Config['UserFilesAbsolutePath'];
$Config['QuickUploadPath']['File'] = $Config['UserFilesAbsolutePath'];

2. 目錄權限

mkdir -p /var/www/html/UserFiles
chmod 777 /var/www/html/UserFiles
chown www-data:www-data /var/www/html/UserFiles

四、PHP 頁面整合範例

<?php
require_once('fckeditor/fckeditor.php');
$oFCKeditor = new FCKeditor('content');
$oFCKeditor->BasePath = '/fckeditor/';
$oFCKeditor->ToolbarSet = 'Basic';
$oFCKeditor->Value = '<p>初始內容</p>';
$oFCKeditor->Create();
?>

五、常見問題

  • 上傳失敗:檢查 config.php 路徑、目錄權限、PHP upload_max_filesize/post_max_size。
  • 中文亂碼:確保 fckconfig.js 以 UTF-8 儲存,PHP 頁面 header('Content-Type: text/html; charset=utf-8')。
  • 圖片不顯示:檢查 UserFilesPath URL 是否可正常訪問。

遷移建議

FCKeditor 已停止維護,新專案強烈建議使用 CKEditor 4/5,架構更現代、支援模組化、相容性更佳。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved