2019-09-10 13:23:30 4484瀏覽
本篇文章扣丁學(xué)堂PHP培訓(xùn)小編為大家詳細(xì)介紹一下PHP搭建百度Ueditor富文本編輯器的方法,文中有詳細(xì)的代碼列出供小伙伴們參考,對PHP開發(fā)感興趣的小伙伴就隨小編來了解一下吧。
下載UEditor
將下載好的文件解壓到thinkphp項目中,本文是解壓到PUBLIC目錄下并改文件夾名稱為ueditor。
第一步 引入javascript
在html中如入下面的js語句引入相關(guān)文件
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
第二步 添加textare文本域并設(shè)置id值
<textarea type="text" name="content" id="EditorId" placeholder="請輸入內(nèi)容"></textarea>
第三步 初始化UEditor編輯器
在html代碼中添加下面的代碼初始化UEditor編譯器
<script type="text/javascript" charset="utf-8">//初始化編輯器 window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路徑設(shè)定為UEditor所放的位置 window.onload=function(){ window.UEDITOR_CONFIG.initialFrameHeight=600;//編輯器的高度 window.UEDITOR_CONFIG.initialFrameWidth=1200;//編輯器的寬度 var editor = new UE.ui.Editor({ imageUrl : '', fileUrl : '', imagePath : '', filePath : '', imageManagerUrl:'', //圖片在線管理的處理地址 imageManagerPath:'__ROOT__/' }); editor.render("EditorId");//此處的EditorId與<textarea name="content" id="EditorId">的id值對應(yīng) </textarea> } </script>
第四步 設(shè)置圖片上傳路徑
UEditor編輯器的默認(rèn)圖片上傳路徑是根目錄下/ueditor/php/upload/image/目錄,沒有這個目錄會自動創(chuàng)建,如果要自定義圖片上傳路徑,可以在ueditor/php/config.json文件中12行處修改。
最后貼上完整的html代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.js"></script> </head> <body> <form action="__URL__/receiver" method="post" accept-charset="utf-8"> <textarea type="text" name="content" id="EditorId" placeholder="請輸入內(nèi)容"></textarea> <input type="submit" value="提交"> </form> <script type="text/javascript" charset="utf-8">//初始化編輯器 window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";//配置路徑設(shè)定為UEditor所放的位置 window.onload=function(){ window.UEDITOR_CONFIG.initialFrameHeight=600;//編輯器的高度 window.UEDITOR_CONFIG.initialFrameWidth=1200;//編輯器的寬度 var editor = new UE.ui.Editor({ imageUrl : '', fileUrl : '', imagePath : '', filePath : '', imageManagerUrl:'', //圖片在線管理的處理地址 imageManagerPath:'__ROOT__/' }); editor.render("EditorId");//此處的EditorId與<textarea name="content" id="EditorId">的id值對應(yīng) </textarea> } </script> </body> </html>
想要了解更多關(guān)于PHP開發(fā)方面內(nèi)容的小伙伴,請關(guān)注扣丁學(xué)堂PHP培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育有專業(yè)的PHP講師為您指導(dǎo),此外扣丁學(xué)堂老師精心推出的PHP視頻教程定能讓你快速掌握PHP從入門到精通開發(fā)實戰(zhàn)技能??鄱W(xué)堂PHP技術(shù)交流群:374332265。
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進入JavaEE/微服務(wù)VIP免費公開課】
查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>