百度編輯器圖片上傳Js
ueditor.all.min.js 下載鏈接
鏈接:https://pan.baidu.com/s/1VNgw9ELgRRHKeCQheFkQTw
提取碼:fnfi
使用方法:
替換原來的 ueditor.all.min.js
NPM 本地快速DEMO:( 前端 )
創建一個文件夾:執行如下命令; 再到瀏覽器運行 localhost:3000 ;( 需要配置本地服務器:修改ueditor.config.js 文件的 serverUrl 的值為本地服務器域名入口,默認為:http://192.168.3.25:19998/index/index/hello )
npm i xuguo_ue && cd node_modules/xuguo_ue && node index.js
注:PHP需要開啟跨域:
header('Access-Control-Allow-Origin:*');header('Access-Control-Allow-Methods: GET,POST,OPTIONS,DELETE,PUT');header('Access-Control-Allow-Headers: Origin,Content-Type, Accept, Authorization, X-Request-With');header('Access-Control-Allow-Credentials: true');header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
問題:
只是實現了圖片的上傳與 Dom 的載入,本人為不改變原生百度的編輯的通用邏輯,圖片路徑顯示依然是相對路徑;
注:當使用PHP Thinkphp 5.1時,如果在使用 ROUTE 並只在 模塊里添加跨域代碼。會導致不能成功跨域。
//解決方法一是修改為默認路由方式(/module/controller/action);
//解決方法二是配置ROUTE路由跨域:以下代碼作為參考
Route::get('new/:id', 'News/read')
->header('Access-Control-Allow-Origin','*')
->header('Access-Control-Allow-Methods','GET,POST,OPTIONS,DELETE,PUT')
->header('Access-Control-Allow-Headers','Origin,Content-Type, Accept, Authorization, X-Request-With')
->header('Access-Control-Allow-Credentials', 'true')
->header('Access-Control-Allow-Headers', 'X-Requested-With,X_Requested_With')
->allowCrossDomain();
注如:PHP 使用 Composer 加載使用:composer require xuying/ueditor;(默認路由:domain.com/ueditor ;因默認路由與保存圖片的地址相同,請自配置config.json).然后創建控制器添加如下代碼。
//添加對應控制器,將下面代碼插入
header('Access-Control-Allow-Origin:*');header('Access-Control-Allow-Methods: GET,POST,OPTIONS,DELETE,PUT');header('Access-Control-Allow-Headers: Origin,Content-Type, Accept, Authorization, X-Request-With');header('Access-Control-Allow-Credentials: true');header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');$config_file = __DIR__ . '/../config.json'; //fixme 使用自定義config.json路徑
$ss = new Control($config_file);//初始化
$ss->index();//運行
解決思路:
使用過濾(正則)的方式進行交互;(目前推薦)
使用CDN的方式配置整體BaseUrl ;

PHP 配置輸出域名:如列:(可暫時使用)

缺點:導致數據庫數據包含了域名,搬家時需要注意資源內容的訪問。
問題:我們可以在提交時過濾掉內容包含的域名,但是編輯器內容豐富,有可能是其它外部的資源,這樣為內容替換增加了難度。
--