PHP中CKEditor和CKFinder配置

來源:互聯網
上載者:User

標籤:style   http   color   io   ar   使用   strong   sp   檔案   

 1、/ckeditor/config.js, 設定檔,如果不想寫太多,可以直接寫好預設配置(語言,功能表列,寬度),有需要可以百度config配置

config.language = ‘en’;config.skin = ‘v2’;config.uiColor = ‘#AADC6E’;config.toolbar = ‘Basic’;…。

2、官方的demo大多都喜歡用js配置editor地區,習慣寫php的我就嫌麻煩,只好看內建的php類。

require_once ROOTPATH 。 “ckeditor/ckeditor.php”;$CKEditor = new CKEditor();$CKEditor-》returnOutput = true; //設定輸出可用變數的情況$CKEditor-》basePath = ‘/ckeditor/’;//設定路徑$contentarea = $CKEditor-》editor(“content”, $rs[‘contents’]); //產生一個以name為content的textarea

echo $contentarea;

3、需要上傳了 ,只好加入ckfinder.把ckfinder和ckeditor放在同級目錄下。

開啟/ckfinder/config.php, 首先設定第一個函數CheckAuthentication(),這個函數需要按照自己的規則寫,只要return true的情況才能允許上傳檔案到伺服器的,當然不建議直接寫return true,這將導致安全問題。可以採用session來處理比較方便。

session_start();function CheckAuthentication(){ if(isset($_SESSION[‘UseEidtor’]))

return true;else return false;}

4、上傳檔案位置:也在/ckfinder/config.php, 找到$baseUrl,之前一直想自己寫一個方法用來定位路徑,實在不好辦,後來只好用sesssion,如果一個網站中,有需要上傳到不同的足浴粉位置,正好可以利用session定位。

if (isset($_SESSION[‘UseEidtor’])) {

switch ($_SESSION[‘UseEidtor’]) { case ‘Addr1’:$baseUrl = ‘/addr1/uploadfile/’;case ‘Addr2’:$baseUrl = ‘/addr2/upfiles/’;}

} else {

$baseUrl = ‘/upfiles/’;

} 5、對於上傳檔案名稱,ckfinder會按照原有的名字命名,中文的情況下可能會亂碼,所以建議使用日期重新命名。開啟/ckfinder/core/connector/php/php5/CommandHandler/FileUpload.php 找到《 /p》

$sUnsafeFileName =CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile[‘name’]));後面加上

$sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sUnsafeFileName);$sUnsafeFileName=date(‘YmdHis’)。‘。’.$sExtension;6、 最後就是使用ckfinder

require_once ROOTPATH 。 “ckeditor/ckeditor.php”;require_once ROOTPATH 。 ‘ckfinder/ckfinder.php’ ;

$CKEditor = new CKEditor();$CKEditor-》returnOutput = true;$CKEditor-》basePath = ‘/ckeditor/’;

CKFinder::SetupCKEditor($CKEditor, ‘/ckfinder/’) ;//注意這裡是相對路徑,相對於根目錄,不能用絕對路徑

$contentarea = $CKEditor-》editor(“content”, $rs[‘contents’]);兩者配合用起來還是挺不錯的,更重要的原因是安全性高了很多。

PHP中CKEditor和CKFinder配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.