Ueditor路徑配置(上傳圖片及視頻)

由于Ueditor編輯器的圖片上傳后,默認(rèn)存儲(chǔ)位置是在www根目錄下,而不是在網(wǎng)站項(xiàng)目目錄下,因此需要重新配置。由于網(wǎng)站項(xiàng)目名有多個(gè),因此需要?jiǎng)討B(tài)與存儲(chǔ)地址進(jìn)行拼接。(等不及的可以直接拉到最后看總結(jié)的步驟)

config.json

修改上傳保存路徑(自定義路徑)

"imagePathFormat": "/Public/Home/ueditor/attached/image/{yyyy}{mm}{dd}/{time}{rand:6}",

Uploader.class.php

private function getFilePath()

? ? {

? ? ? ? $fullname = $this->fullName;

? ? ? ? $rootPath = $_SERVER['DOCUMENT_ROOT'];

????????$filePath=$_SERVER['PHP_SELF'];

????????$arr=explode("/", $filePath);

????????$serverName=$arr[1]; //得到項(xiàng)目名稱

? ? ? ? if (substr($fullname, 0, 1) != '/') {

? ? ? ? ? ? $fullname = '/' . $fullname;

? ? ? ? }

? ? ? ? //echo $rootPath . '/'.$serverName.$fullname; exit;

? ? ? ? return $rootPath . '/'.$serverName.$fullname;

? ?}

可以輸出最終return的結(jié)果查看(取消echo那一行注釋代碼在network中可查看) 為:本地圖片地址

D:/phpStudy/WWW/yk/Public/Home/ueditor/attached/image/20180613/1528881946312238.jpg

yk是動(dòng)態(tài)的項(xiàng)目名稱,此結(jié)果得到的是動(dòng)態(tài)的圖片地址。即使更換其他項(xiàng)目名稱也沒(méi)關(guān)系。

但是編輯器中,圖片顯示路徑有問(wèn)題,后臺(tái)返回的圖片地址并沒(méi)有帶上項(xiàng)目名稱yk,因此無(wú)法顯示。


如果項(xiàng)目名稱是唯一的,當(dāng)然可以通過(guò)設(shè)置

config.json

"imageUrlPrefix": "/項(xiàng)目名",

來(lái)讓圖片顯示出來(lái)。但是開(kāi)始的問(wèn)題就是項(xiàng)目名稱并不是唯一的。因此不能在這里將imageUrlPrefix設(shè)置死。

解決辦法:

config.json

"imageUrlPrefix": "",

這一行保持空,不要?jiǎng)印?/p>

controller.php

$filePath=$_SERVER['PHP_SELF'];

$arr=explode("/", $filePath);

$serverName=$arr[1];? ?//得到項(xiàng)目名

switch ($action) {

????case 'config':

????????if(isset($CONFIG["imageUrlPrefix"])){

????????????$CONFIG["imageUrlPrefix"]="/".$serverName;? ?//動(dòng)態(tài)設(shè)置imageUrlPrefix

????????}

????????$result = json_encode($CONFIG);

????????break;

............

思路:將項(xiàng)目名稱動(dòng)態(tài)的加到返回到編輯器中的url中。即動(dòng)態(tài)設(shè)置imageUrlPrefix的值。

視頻上傳:

config.json? 視頻保存路徑修改成自己需要的

"videoPathFormat": "/Public/Home/ueditor/attached/video/{yyyy}{mm}{dd}/{time}{rand:6}",

Uploader.class.php,此修改和圖片是一樣的,都是動(dòng)態(tài)加載存儲(chǔ)的項(xiàng)目名

private function getFilePath() {

????$fullname = $this->fullName;

????$rootPath = $_SERVER['DOCUMENT_ROOT'];

? ? $filePath=$_SERVER['PHP_SELF'];

? ? $arr=explode("/", $filePath);

? ? $serverName=$arr[1];

????if (substr($fullname, 0, 1) != '/') {

????????$fullname = '/' . $fullname;

????}

????return $rootPath . '/'.$serverName.$fullname;

}

controller.php

$filePath=$_SERVER['PHP_SELF'];

$arr=explode("/", $filePath);

$serverName=$arr[1];

switch ($action) {

? case 'config':

? ? if(isset($CONFIG["imageUrlPrefix"])){? ? //圖片訪問(wèn)路徑前綴

? ? ? $CONFIG["imageUrlPrefix"]="/".$serverName;

? ? }

? ? if(isset($CONFIG["videoUrlPrefix"])){???//視頻訪問(wèn)路徑前綴

? ? ? $CONFIG["videoUrlPrefix"]="/".$serverName;

? ? }

? $result = json_encode($CONFIG);

? break;

......

以下ueditor.all.js的配置可以讓視頻在編輯器中能夠播放,但是提交到數(shù)據(jù)庫(kù)的時(shí)候會(huì)存在一些問(wèn)題,即內(nèi)容僅為視頻時(shí)ue.getContent()獲取到的編輯器中的內(nèi)容為空,只有當(dāng)輸入其他字符時(shí),ue.getContent()才能獲取到編輯器中的內(nèi)容。因此不推薦修改下面ueditor.all.js中的內(nèi)容。

ueditor.all.js

7343,7344,7345三行注釋掉

// var root = UE.htmlparser(html);

// me.filterInputRule(root);

// html = root.toHtml();

17769行? image改成video

// html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));

html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'video'));

其實(shí)出現(xiàn)上傳視頻后在編輯器中一片空白的情況,查看HTML源碼src丟失,可將

ueditor.config.js? 第365行??whitList修改為whiteList

修改后編輯器中上傳視頻的效果


這樣改了之后,編輯器中的視頻內(nèi)容是可以通過(guò)ue.getContent()獲取到的。

總結(jié):

路徑配置:

①在config.json中配置上傳圖片或視頻的保存路徑,不帶項(xiàng)目名稱的。

"imagePathFormat": "/Public/Home/ueditor/attached/image/{yyyy}{mm}{dd}/{time}{rand:6}",? //圖片

"scrawlPathFormat": "/Public/Home/ueditor/attached/image/{yyyy}{mm}{dd}/{time}{rand:6}",? //視頻

"videoPathFormat": "/Public/Home/ueditor/attached/video/{yyyy}{mm}{dd}/{time}{rand:6}",? //涂鴉

②在Uploader.class.php中,修改文件的完整路徑,主要是動(dòng)態(tài)添加項(xiàng)目名稱。

private function getFilePath() {????

????$fullname = $this->fullName;????

????$rootPath = $_SERVER['DOCUMENT_ROOT'];????

? ? $filePath=$_SERVER['PHP_SELF'];

? ? $arr=explode("/", $filePath);

? ? $serverName=$arr[1];? ?//得到項(xiàng)目名

????if (substr($fullname, 0, 1) != '/') {????????

????????$fullname = '/' . $fullname;????

????}????

????return $rootPath . '/'.$serverName.$fullname;

}

③在controller.php中,動(dòng)態(tài)設(shè)置圖片或視頻的訪問(wèn)路徑前綴。

$filePath=$_SERVER['PHP_SELF'];

$arr=explode("/", $filePath);

$serverName=$arr[1];? ?//得到項(xiàng)目名

switch ($action) {

case 'config':

if(isset($CONFIG["imageUrlPrefix"])){ $CONFIG["imageUrlPrefix"]="/".$serverName; }?//圖片 if(isset($CONFIG["videoUrlPrefix"])){ $CONFIG["videoUrlPrefix"]="/".$serverName; }?//視頻 if(isset($CONFIG["scrawlUrlPrefix"])){ $CONFIG["scrawlUrlPrefix"]="/".$serverName; }?//涂鴉

$result = json_encode($CONFIG);

break;

......

④修改ueditor.config.js

第365行??whitList 修改為 whiteList

以上就是全部步驟。如果還有其他更好方法,歡迎一起分享。

前端HTML引用請(qǐng)查看官方示例吧(或查看我寫的簡(jiǎn)單示例)。

ps:關(guān)于視頻音頻上傳還可以參考這個(gè)帖子,有興趣的可以試驗(yàn)下。

以下是我參考的一些資料:

http://ueditor.baidu.com/website/document.html

http://fex.baidu.com/ueditor/#start-config

圖片上傳路徑配置參考:http://www.cnblogs.com/liugx/p/6907584.html

視頻上傳配置參考:https://blog.csdn.net/eadela/article/details/76264168

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容