fckeditor是一款開源多功能的常見的強大編輯器,如在論壇上發表文章時,其實用到的就是fckeditor編輯器。寫個總結帖記下fckeditor的配置說明,供phpers參考。
1.下載fckeditor(下載地址:http://ckeditor.com/)
2.更改fckconfig.js文件的配置
FCKConfig.AutoDetectLanguage = true ;改爲FCKConfig.AutoDetectLanguage = false ;(不讓其自動判斷而加載語言)
FCKConfig.DefaultLanguage = ‘en’ ;改爲FCKConfig.DefaultLanguage = ‘zh-cn’ ;(設置爲中文)
FCKConfig.FontNames改爲 FCKConfig.FontNames= ‘宋體;黑體;隸書;楷體_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana’ ;(設置字體)
FCKConfig.FontSizes改爲FCKConfig.FontSizes = ’9px;10px;11px;12px;13px;14px;16px;18px;24px;36px’ ;(設置大小)
var _FileBrowserLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py(如果這兩項是php則不用修改,否則改之)
【開啓瀏覽服務器功能】
FCKConfig.LinkBrowser = true ;
FCKConfig.ImageBrowser = true ;
【開啓上傳功能】
FCKConfig.LinkUpload = true ;
FCKConfig.ImageUpload = true ;
FCKConfig.FlashUpload = true ;
【設置上傳路徑】
打開文件editor\filemanager\connectors\php\config.php,$Config['Enabled'] = false ;改爲$Config['Enabled'] = true ;
$Config['UserFilesPath'] = ‘/fckeditor/upload/’ ;//fckeditor爲插件根目錄,將上傳附件放於upload文件夾下
$Config['QuickUploadPath']['File'] = $Config['UserFilesPath'] ;
$Config['QuickUploadPath']['Image'] = $Config['UserFilesPath'] ;
$Config['QuickUploadPath']['Flash'] = $Config['UserFilesPath'] ;
$Config['QuickUploadPath']['Media'] = $Config['UserFilesPath'] ;
分別改爲:
$Config['QuickUploadPath']['File'] = $Config['UserFilesPath'].'file/' ;
$Config['QuickUploadPath']['Image'] = $Config['UserFilesPath'].'p_w_picpath/' ;
$Config['QuickUploadPath']['Flash'] = $Config['UserFilesPath'].'flash/' ;
$Config['QuickUploadPath']['Media'] = $Config['UserFilesPath'].'media/' ;
【上傳功能優化】
測試上傳功能,上傳英文名字的文件沒有問題,但如果文件名有漢字,那麼會出現亂碼,可有兩種解決方案,一種是讓上傳支 持中文名,使用這種方案可能會出現文件名重複的現象,另外中文文件名的下載會有些問題;另一種是用當前時間戳做爲文件名,下面針對兩種方案給出實現,可根 據具體情況進行選擇。
方案一 讓fckeditor在php環境中支持中文名上傳
打開fckeditor/editor/filemanager/connectors/php/commands.php找到 $sFileName = $oFile['name'] ; 改爲$sFileName = iconv("utf-8","gbk",$oFile['name']) ;
打開fckeditor/editor/filemanager/connectors/php/commands.php找到 $sFileName = $oFile['name'] ;改爲$sFileName = time().".".strtolower(array_pop(explode(".",$oFile['name'])));
【引入fckeditor編輯器】
<?php include('fckeditor.php') ; $sBasePath = $_SERVER['PHP_SELF'] ; $sBasePath = dirname($sBasePath).'/'; $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = $sBasePath ; $oFCKeditor->Value = ''; $oFCKeditor->Create(); ?>
【fckeditor與數據庫結合使用】
<?php include('fckeditor.php') ; $sBasePath = $_SERVER['PHP_SELF'] ; $sBasePath = dirname($sBasePath).'/'; $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = $sBasePath ; $conn=mysql_connect('localhost','root','123456'); $conndb=mysql_select_db('net',$conn); $sql="insert into text(content) values('$_POST[FCKeditor1]')"; //$_POST鍵名必須與實例化FCKeditor類時的參數一致 if(mysql_query($sql)){ echo "插入成功"; } $selsql="select * from text"; $squery=mysql_query($sesql); while($result=mysql_fetch_array($sq)){ echo $result['content']; } ?> <form action="" method="post"> <?php $oFCKeditor->Create() ;?> <input type="submit" name="submit" value="確定提交"/> </form>
轉自:http://iecspace.ecjtu.org/posts/fckeditor-config