百度编辑器图片上传Js
ueditor.all.min.js 下载连接php
连接:https://pan.baidu.com/s/1VNgw9ELgRRHKeCQheFkQTw
提取码:fnfi
前端
使用方法:node
替换原来的 ueditor.all.min.js 数据库
NPM 本地快速DEMO:( 前端 )npm
建立一个文件夹:执行以下命令; 再到浏览器运行 localhost:3000 ;( 须要配置本地服务器:修改ueditor.config.js 文件的 serverUrl 的值为本地服务器域名入口,默认为:http://192.168.3.25:19998/index/index/hello )json
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 并只在 模块里添加跨域代码。会致使不能成功跨域。composer
//解决方法一是修改成默认路由方式(/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();//运行
解决思路:
缺点:致使数据库数据包含了域名,搬家时须要注意资源内容的访问。
问题:咱们能够在提交时过滤掉内容包含的域名,可是编辑器内容丰富,有多是其它外部的资源,这样为内容替换增长了难度。
--