PHP插件 FCKeditor 編輯器

 思路,做爲一個編輯器插件 FCKeidtor能夠說功能很是全面,下面簡單說下如何在本身的開發項目中使用這個插件php

首先,下載到FCKeidtor這個軟件包 點擊下載html

而後解壓縮複製到項目根目錄 並更名爲比較簡單的名字 editor服務器

首先打開fckeidtor.php 發現做用是判斷服務器的PHP版本,4.0就引入4.0的類,5.0就引入5.0的類編輯器

  
  
  
  
  1. if ( !function_exists('version_compare') || version_compare( phpversion(), '5''<' ) ) 
  2.     include_once'fckeditor_php4.php' ) ; 
  3. else 
  4.     include_once'fckeditor_php5.php' ) ; 

而後新建一個PHP頁面 new_add.php 內容以下ide

  
  
  
  
  1. <?  
  2. /*用include方法加載類的文件,這個文件會自動判斷服務器的PHP版本,4.0自動調用4.0的類,5.0調用5.0的類*/ 
  3. include ("editor/fckeditor.php");  
  4. $oBasePath = $_SERVER['PHP_SELF'];//用$_SERVER函數獲得當前文件的實際路徑,這裏包括文件名  
  5. /*用dirname函數獲得去掉文件名的路徑加上/editor/獲得FCKeditor的路徑*/ 
  6. $oBasePath = dirname ($oBasePath)."/editor/";  
  7. $ed = new FCKeditor("con"); //實例化FCKeditor對象 給name爲con  
  8. $ed->BasePath = $oBasePath//程序的地址爲上面獲得的路徑  
  9. //$ed->ToolbarSet = "Basic"; 是否使用簡單模式的開關  
  10. ?>  
  11. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  12. <html xmlns="http://www.w3.org/1999/xhtml">  
  13. <head>  
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  15. <title>無標題文檔</title>  
  16. </head>  
  17.  
  18. <body>  
  19. <?  
  20.  
  21. if($_POST[sub])//判斷$_POST[sub]是否爲真,真爲有內容提交  
  22.    
  23. {  
  24.     $con = $_POST[con];//讀取FCKeditor中的內容  
  25.     $con = str_replace('\\','',$con); //替換\爲空,爲了讓網址能正常顯示  
  26.     echo "文章標題:".$_POST[title].  
  27.      "<br>文章內容".$con//輸出接收的內容  
  28. }  
  29.  
  30. ?>  
  31. <form method="post" action="">  
  32. 文章標題<input type="text" name="title" />  
  33. <? $ed->Create(); //建立一個FCKeditor的窗口?>   
  34. <input type="submit" name="sub" value="提交新聞" />  
  35. </form>  
  36. </body>  
  37. </html>  
  38.  

最重要的步驟是 函數

  1. $oBasePath = $_SERVER['PHP_SELF'];//用$_SERVER函數獲得當前文件的實際路徑,這裏包括文件名  
  2. /*用dirname函數獲得去掉文件名的路徑加上/editor/獲得FCKeditor的路徑*/ 
  3. $oBasePath = dirname ($oBasePath)."/editor/";  
  4. $ed = new FCKeditor("con"); //實例化FCKeditor對象 給name爲con  
  5. $ed->BasePath = $oBasePath//程序的地址爲上面獲得的路徑  

若是要FCKeditor能夠上傳圖片的話,要開啓editor\editor\filemanager\connectors\php\config.php裏面post

找到 $Config['Enabled'] =  false; 這是默認的ui

修改成 $Config['Enabled'] = true ;spa

找到$Config['UserFilesPath'] = '/userfiles/' ; 這是上傳文件的路徑改成本身的路徑插件

如 $Config['UserFilesPath'] = '/class/userfiles/' ; 就是個人localhost/class/路徑下的userfiles文件夾

相關文章
相關標籤/搜索