TP5配置Ueditor上傳完成視訊-塗鴉-遠端-檔案上傳
廢話不說,直接上程式碼。
一、資源部署
1.1 下載ueditor放到 public/static目錄下,這個根據自己基本的部署來安排資料夾就行。我放在 static/libs/ueditor目錄下
1.2 刪除ueditor目錄下的php目錄或移到別的地方去。靜態目錄下是絕對不允許執行PHP的。
1.3 複製一份 ueditor.config.js 重命令為admin.confg.js這個根據自己喜好哦。
這裡需要處理一下,該配置檔案下有一個 serverUrl引數指向要處理請uediter請求的URL,大概在33行
, serverUrl: "/admin.php/admin/public/ueditor.html"
二、引入檔案
<script type="text/javascript" charset="utf-8" src="/static/libs/ueditor/admin.config.js"></script> <script type="text/javascript" charset="utf-8" src="/static/libs/ueditor/ueditor.all.min.js"> </script> <script type="text/javascript" charset="utf-8" src="/static/libs/ueditor/lang/zh-cn/zh-cn.js"></script> <script id="editor_{$name}" name="{$name}" type="text/plain" style="width:100%;height:500px;"></script> <script>var ue = UE.getEditor('editor_{$name}');</script>
三、寫控制器檔案
class Public extends Admin{ public function ueditor(){ $action = input('action','','filter_keyword'); $callback = input('callback','','filter_keyword'); $myUpload = new UeUpload(); $upConfig = $myUpload->config(); switch ($action){ case 'config': //獲取配置資訊 $result = $upConfig; break; case 'uploadimage': //上傳圖片 $currConfig = [ 'pathFormat' => $upConfig['imagePathFormat'], //配置檔案中圖片方面的配置資料 'maxSize' => $upConfig['imageMaxSize'], 'allowFiles' => $upConfig['imageAllowFiles'], ]; $fieldName = $upConfig['imageFieldName']; $myUpload->upload($fieldName, $currConfig,'upload'); $result = $myUpload->getFileInfo(); break; case 'uploadscrawl': //上傳塗鴉,Base64上傳 $currConfig = array( "pathFormat" => $upConfig['scrawlPathFormat'], "maxSize" => $upConfig['scrawlMaxSize'], "allowFiles" => $upConfig['scrawlAllowFiles'], "oriName" => "scrawl.png" ); $fieldName = $upConfig['scrawlFieldName']; $myUpload->upload($fieldName,$currConfig,'base64'); $result = $myUpload->getFileInfo(); break; case 'uploadvideo': //上傳視訊 $currConfig = array( 'pathFormat' => $upConfig['videoPathFormat'], 'maxSize' => $upConfig['videoMaxSize'], 'allowFiles' => $upConfig['videoAllowFiles'], ); $fieldName = $upConfig['videoFieldName']; $myUpload->upload($fieldName, $currConfig); $result = $myUpload->getFileInfo(); break; case 'uploadfile': //上傳檔案 $currConfig = array( 'pathFormat' => $upConfig['filePathFormat'], 'maxSize' => $upConfig['fileMaxSize'], 'allowFiles' => $upConfig['fileAllowFiles'], ); $fieldName = $upConfig['fileFieldName']; $myUpload->upload($fieldName, $currConfig); $result = $myUpload->getFileInfo(); break; case 'listimage': //列出圖片 $result = include("action_list.php"); break; case 'listfile': //列出檔案 $result = include("action_list.php"); break; /* 抓取遠端檔案 */ case 'catchimage': $currConfig = [ 'pathFormat' => $upConfig['catcherPathFormat'], 'maxSize' => $upConfig['catcherMaxSize'], 'allowFiles' => $upConfig['catcherAllowFiles'], 'oriName' => 'remote.png', //這個配置沒有什麼意義 ]; $fieldName = $upConfig['catcherFieldName']; $result = $myUpload->uploadCrawler($fieldName,$currConfig); break; default: $result = json_encode(['state'=> '請求地址出錯']); break; } if(!empty($callback)){ if (preg_match("/^[\w_]+$/", $_GET["callback"])) { echo htmlspecialchars($callback) . '(' . $result . ')'; } else { echo json_encode(['state'=> 'callback引數不合法']); } }else{ if(is_array($result)){ echo json_encode($result); }else{ echo $result; } } }
控制器裡只負責獲取講求型別,然後轉給UeUpload.class來處理。
四、核心檔案UeUpload類
<?php
namespace app\extend\ueditor;
use think\Config;
use think\Request;
class UeUpload{
private $uploadPath;
private $uplaodPrefix; //上傳路徑字首
private $fileField; //檔案域名
private $file; //檔案上傳物件
private $base64; //檔案上傳物件
private $config; //配置資訊
private $oriName; //原始檔名
private $fileName; //新檔名
private $fullName; //完整檔名,即從當前配置目錄開始的URL
private $filePath; //完整檔名,即從當前配置目錄開始的URL
private $fileSize; //檔案大小
private $fileType; //檔案型別
private $stateInfo; //上傳狀態資訊,
private $stateMap = array( //上傳狀態對映表,國際化使用者需考慮此處資料的國際化
"SUCCESS", //上傳成功標記,在UEditor中內不可改變,否則flash判斷會出錯
"檔案大小超出 upload_max_filesize 限制",
"檔案大小超出 MAX_FILE_SIZE 限制",
"檔案未被完整上傳",
"沒有檔案被上傳",
"上傳檔案為空",
"ERROR_TMP_FILE" => "臨時檔案錯誤",
"ERROR_TMP_FILE_NOT_FOUND" => "找不到臨時檔案",
"ERROR_SIZE_EXCEED" => "檔案大小超出網站限制",
"ERROR_TYPE_NOT_ALLOWED" => "檔案型別不允許",
"ERROR_CREATE_DIR" => "目錄建立失敗",
"ERROR_DIR_NOT_WRITEABLE" => "目錄沒有寫許可權",
"ERROR_FILE_MOVE" => "檔案儲存時出錯",
"ERROR_FILE_NOT_FOUND" => "找不到上傳檔案",
"ERROR_WRITE_CONTENT" => "寫入檔案內容錯誤",
"ERROR_UNKNOWN" => "未知錯誤",
"ERROR_DEAD_LINK" => "連結不可用",
"ERROR_HTTP_LINK" => "連結不是http連結",
"ERROR_HTTP_CONTENTTYPE" => "連結contentType不正確",
"INVALID_URL" => "非法 URL",
"INVALID_IP" => "非法 IP"
);
public function __construct()
{
$this->uploadPath = $uploadPath = Config::get('upload.path');
$this->uploadPreFix = Config::get('upload.url_prefix');
}
public function config(){
$uploadPath = $this->uploadPath;
$config = include APP_PATH . 'extend' . DS . 'ueditor' . DS . 'config.php';
//這裡需要處理下上傳的路徑
$config['imagePathFormat'] = $uploadPath . '{yyyy}{mm}{dd}'; //圖片上傳儲存的路徑
$config['scrawlPathFormat'] = $uploadPath . '{yyyy}{mm}{dd}/{time}_{rand:12}'; //塗鴉儲存路徑
$config['snapscreenPathFormat'] = $uploadPath . '{yyyy}{mm}{dd}'; //截圖工具儲存路徑
$config['catcherPathFormat'] = $uploadPath . '{yyyy}{mm}{dd}/remote_{time}_{rand:4}'; //遠端抓取儲存路徑
$config['videoPathFormat'] = $uploadPath . '{yyyy}{mm}{dd}/video_{time}'; //視訊上傳路徑
$config['filePathFormat'] = $uploadPath . '{yyyy}{mm}{dd}/file_{time}'; //檔案上傳配置
$config['imageManagerListPath'] = $uploadPath . '{yyyy}{mm}{dd}'; //列出指定目錄下的圖片
$config['fileManagerListPath'] = $uploadPath . '{yyyy}{mm}{dd}'; //列出指定目錄下的檔案
return $config;
}
/**
*
* @param string $fileField 表單名稱
* @param array $config 配置項
* @param bool $base64 是否解析base64編碼,可省略。若開啟,則$fileField代表的是base64編碼的字串表單名
*/
public function upload($fileField, $config, $type = "upload")
{
$this->fileField = $fileField;
$this->config = $config;
$this->type = $type;
if ($type == "remote") { //接取遠端圖片
$this->saveRemote();
} else if($type == "base64") { //base64圖片上傳
$this->upBase64();
} else {
$this->upFile();
}
$this->stateMap['ERROR_TYPE_NOT_ALLOWED'] = iconv('unicode', 'utf-8', $this->stateMap['ERROR_TYPE_NOT_ALLOWED']);
}
/**
* 上傳檔案的主處理方法
* @return mixed
*/
private function upFile()
{
$fileObj = request()->file($this->fileField);
try{
$file = $this->file = $fileObj->getInfo();
}catch (\Exception $e){
$this->stateInfo = '上傳失敗';
return;
}
if($file){
if($file['error']){
$this->stateInfo = $this->getStateInfo($file['error']);
return;
}
//2.檢查臨時檔案是否存在
if(!file_exists($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
return;
}
//3.是否為上傳檔案
if (!is_uploaded_file($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
return;
}
$this->oriName = $file['name'];
$this->fileSize = $file['size'];
$this->fileType = $this->getFileExt();
$this->fullName = $this->getFullName();
$this->filePath = $this->getFilePath();
$this->fileName = $this->getFileName();
//echo $this->fileName;exit();
//檢查檔案大小是否超出限制
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//檢查是否不允許的檔案格式
if (!$this->checkType()) {
$this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
return;
}
//Move之前可以結合 validate() 對上傳檔案進行校驗
//副檔名,TP中的校驗是沒有.的,Ueditor裡的配置是有點的。所以這裡要去掉這個點。
$valiData = [
'size' => $this->config['maxSize'], //大小
'ext' => str_replace('.', '', implode(',',$this->config['allowFiles']))
];
//移動檔案
$moveResult = $fileObj->validate($valiData)->move($this->uploadPath,$this->fileName);
if($moveResult){
$this->fullName = $this->uploadPreFix . str_replace('\\','/',$moveResult->getSaveName());
$this->stateInfo = $this->stateMap[0];
}else{
$this->stateInfo = $fileObj->getError();
}
return;
}else{
$this->stateInfo = $this->getStateInfo('ERROR_FILE_NOT_FOUND');
return;
}
}
/**
* 處理base64編碼的圖片上傳
* @return mixed
*/
private function upBase64()
{
$base64Data = Request()->post($this->fileField);
$img = base64_decode($base64Data);
$this->oriName = $this->config['oriName'];
$this->fileSize = strlen($img);
$this->fileType = $this->getFileExt();
$this->fullName = $this->getFullName();
$this->filePath = $this->getFilePath(); //路徑,無檔名
$this->fileName = $this->getFileName();
$dirname = dirname($this->filePath);
//檢查檔案大小是否超出限制
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//建立目錄失敗
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
return;
} else if (!is_writeable($dirname)) {
$this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
}
//移動檔案
if (!(file_put_contents($this->filePath, $img) && file_exists($this->filePath))) { //移動失敗
$this->stateInfo = $this->getStateInfo("ERROR_WRITE_CONTENT");
} else { //移動成功
//由於配置上傳路徑的是時候是./開頭的,所以這裡要把第一個點給去掉,否則URL路徑出錯
if(substr($this->fullName,0,2) == './'){
$this->fullName = substr($this->fullName, 1,strlen($this->fullName));
}
$this->stateInfo = $this->stateMap[0];
}
}
/**
* 拉取遠端圖片
* @return mixed
*/
private function saveRemote($imgUrl)
{
$imgUrl = htmlspecialchars($imgUrl);
$imgUrl = str_replace("&", "&", $imgUrl);
//echo $imgUrl;
//http開頭驗證
if (strpos($imgUrl, "http") !== 0) {
$this->stateInfo = $this->getStateInfo("ERROR_HTTP_LINK");
return;
}
preg_match('/(^https*:\/\/[^:\/]+)/', $imgUrl, $matches);
$host_with_protocol = count($matches) > 1 ? $matches[1] : '';
// 判斷是否是合法 url
if (!filter_var($host_with_protocol, FILTER_VALIDATE_URL)) {
$this->stateInfo = $this->getStateInfo("INVALID_URL");
return;
}
preg_match('/^https*:\/\/(.+)/', $host_with_protocol, $matches);
$host_without_protocol = count($matches) > 1 ? $matches[1] : '';
// 此時提取出來的可能是 ip 也有可能是域名,先獲取 ip
$ip = gethostbyname($host_without_protocol);
// 判斷是否是私有 ip
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
$this->stateInfo = $this->getStateInfo("INVALID_IP");
return;
}
//獲取請求頭並檢測死鏈
$heads = get_headers($imgUrl, 1);
if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
$this->stateInfo = $this->getStateInfo("ERROR_DEAD_LINK");
return;
}
//格式驗證(副檔名驗證和Content-Type驗證)
$fileType = strtolower(strrchr($imgUrl, '.'));
if (!in_array($fileType, $this->config['allowFiles']) || !isset($heads['Content-Type']) || !stristr($heads['Content-Type'], "image")) {
$this->stateInfo = $this->getStateInfo("ERROR_HTTP_CONTENTTYPE");
return;
}
//開啟輸出緩衝區並獲取遠端圖片
ob_start();
$context = stream_context_create(
array('http' => array(
'follow_location' => false // don't follow redirects
))
);
readfile($imgUrl, false, $context);
$img = ob_get_contents();
ob_end_clean();
preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m);
$this->oriName = $m ? $m[1]:"";
$this->fileSize = strlen($img);
$this->fileType = $this->getFileExt();
$this->fullName = $this->getFullName();
$this->filePath = $this->getFilePath();
$this->fileName = $this->getFileName();
$dirname = dirname($this->filePath);
//檢查檔案大小是否超出限制
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//建立目錄失敗
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
return;
} else if (!is_writeable($dirname)) {
$this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
}
//移動檔案
if (!(file_put_contents($this->filePath, $img) && file_exists($this->filePath))) {
//移動失敗
$this->stateInfo = $this->getStateInfo("ERROR_WRITE_CONTENT");
} else {
//移動成功
if(substr($this->fullName,0,2) == './'){
$this->fullName = substr($this->fullName, 1,strlen($this->fullName));
}
$this->stateInfo = $this->stateMap[0];
}
}
/**
* 上傳錯誤檢查
* @param $errCode
* @return string
*/
private function getStateInfo($errCode)
{
return !$this->stateMap[$errCode] ? $this->stateMap["ERROR_UNKNOWN"] : $this->stateMap[$errCode];
}
/**
* 獲取副檔名
* @return string
*/
private function getFileExt()
{
return strtolower(strrchr($this->oriName, '.'));
}
/**
* 重新命名檔案
* @return string
*/
private function getFullName()
{
//替換日期事件
$t = time();
$d = explode('-', date("Y-y-m-d-H-i-s"));
$format = $this->config["pathFormat"];
$format = str_replace("{yyyy}", $d[0], $format);
$format = str_replace("{yy}", $d[1], $format);
$format = str_replace("{mm}", $d[2], $format);
$format = str_replace("{dd}", $d[3], $format);
$format = str_replace("{hh}", $d[4], $format);
$format = str_replace("{ii}", $d[5], $format);
$format = str_replace("{ss}", $d[6], $format);
$format = str_replace("{time}", $t, $format);
//過濾檔名的非法字元,並替換檔名
$oriName = substr($this->oriName, 0, strrpos($this->oriName, '.'));
$oriName = preg_replace("/[\|\?\"\<\>\/\*\\\\]+/", '', $oriName);
$format = str_replace("{filename}", $oriName, $format);
//替換隨機字串
$randNum = create_randomstr(64);
if (preg_match("/\{rand\:([\d]*)\}/i", $format, $matches)) {
$format = preg_replace("/\{rand\:[\d]*\}/i", substr($randNum, 0, $matches[1]), $format);
}
$ext = $this->getFileExt();
return $format . $ext;
}
/**
* 獲取檔名
* @return string
*/
private function getFileName () {
return substr($this->filePath, strrpos($this->filePath, '/') + 1);
}
/**
* 獲取檔案完整路徑
* @return string
*/
private function getFilePath()
{
$fullname = $this->fullName;
$rootPath = $_SERVER['DOCUMENT_ROOT'];
if (substr($fullname, 0, 1) != '/') {
$fullname = '/' . $fullname;
}
return $rootPath . $fullname;
}
/**
* 檔案型別檢測
* @return bool
*/
private function checkType()
{
return in_array($this->getFileExt(), $this->config["allowFiles"]);
}
/**
* 檔案大小檢測
* @return bool
*/
private function checkSize()
{
return $this->fileSize <= ($this->config["maxSize"]);
}
/**
* 獲取當前上傳成功檔案的各項資訊
* @return array
*/
public function getFileInfo()
{
return array(
"state" => $this->stateInfo,
"url" => $this->fullName,
"title" => $this->fileName,
"original" => $this->oriName,
"type" => $this->fileType,
"size" => $this->fileSize
);
}
/**
* 遠端檔案轉換
* @param $fielField
* @param $config
* @return array
* @auther hotlinhao
*/
public function uploadCrawler($fielField,$config){
$this->fileField = $fielField;
$this->config = $config;
$postSource = Request()->post($this->fileField . '/a');
if(is_array($postSource) && count($postSource) > 0){
$source = $postSource;
}else{
$source = Request()->get($this->fileField.'/a');
}
$list=[];
foreach ($source as $imgUrl){
$this->saveRemote($imgUrl);
$info = $this->getFileInfo();
array_push($list, [
'state' => $info['state'],
'url' => $info['url'],
'size' => $info['size'],
'title' => htmlspecialchars($info['title']),
'source' => htmlspecialchars($imgUrl)
]);
}
return [
'state' => count($list) ? 'SUCCESS' : 'ERROR',
'list' => $list
];
}
public function lists(){
}
}
將原配置檔案轉換為陣列放到 extend/ueditor目錄下,命名為 config.php ,因為上傳路徑在JSON檔案中都是寫死的,無法和後臺引數等配合使用,所以這裡採用動態引入的方法,然後再自行修改處理。
<?php
/* 前後端通訊相關的配置,註釋只允許使用多行方式 */
return [
/* 上傳圖片配置項 */
"imageActionName" => "uploadimage", /* 執行上傳圖片的action名稱 */
"imageFieldName" => "upfile", /* 提交的圖片表單名稱 */
"imageMaxSize" => 2048000, /* 上傳大小限制,單位B */
"imageAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上傳圖片格式顯示 */
"imageCompressEnable" => true, /* 是否壓縮圖片,預設是true */
"imageCompressBorder" => 1600, /* 圖片壓縮最長邊限制 */
"imageInsertAlign" => "none", /* 插入的圖片浮動方式 */
"imageUrlPrefix" => "", /* 圖片訪問路徑字首 */
"imagePathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
/* {filename} 會替換成原檔名,配置這項需要注意中文亂碼問題 */
/* {rand:6} 會替換成隨機數,後面的數字是隨機數的位數 */
/* {time} 會替換成時間戳 */
/* {yyyy} 會替換成四位年份 */
/* {yy} 會替換成兩位年份 */
/* {mm} 會替換成兩位月份 */
/* {dd} 會替換成兩位日期 */
/* {hh} 會替換成兩位小時 */
/* {ii} 會替換成兩位分鐘 */
/* {ss} 會替換成兩位秒 */
/* 非法字元 \ : * ? " < > | */
/* 具請體看線上文件: fex.baidu.com/ueditor/#use-format_upload_filename */
/* 塗鴉圖片上傳配置項 */
"scrawlActionName" => "uploadscrawl", /* 執行上傳塗鴉的action名稱 */
"scrawlFieldName" => "upfile", /* 提交的圖片表單名稱 */
"scrawlPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
"scrawlMaxSize" => 2048000, /* 上傳大小限制,單位B */
"scrawlUrlPrefix" => "", /* 圖片訪問路徑字首 */
"scrawlInsertAlign" => "none",
/* 截圖工具上傳 */
"snapscreenActionName" => "uploadimage", /* 執行上傳截圖的action名稱 */
"snapscreenPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
"snapscreenUrlPrefix" => "", /* 圖片訪問路徑字首 */
"snapscreenInsertAlign" => "none", /* 插入的圖片浮動方式 */
/* 抓取遠端圖片配置 */
"catcherLocalDomain" => ["127.0.0.1", "localhost", "img.baidu.com"],
"catcherActionName" => "catchimage", /* 執行抓取遠端圖片的action名稱 */
"catcherFieldName" => "source", /* 提交的圖片列表表單名稱 */
"catcherPathFormat" => "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
"catcherUrlPrefix" => "", /* 圖片訪問路徑字首 */
"catcherMaxSize" => 2048000, /* 上傳大小限制,單位B */
"catcherAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取圖片格式顯示 */
/* 上傳視訊配置 */
"videoActionName" => "uploadvideo", /* 執行上傳視訊的action名稱 */
"videoFieldName" => "upfile", /* 提交的視訊表單名稱 */
"videoPathFormat" => "/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
"videoUrlPrefix" => "", /* 視訊訪問路徑字首 */
"videoMaxSize" => 102400000, /* 上傳大小限制,單位B,預設100MB */
"videoAllowFiles" => [
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上傳視訊格式顯示 */
/* 上傳檔案配置 */
"fileActionName" => "uploadfile", /* controller裡,執行上傳視訊的action名稱 */
"fileFieldName" => "upfile", /* 提交的檔案表單名稱 */
"filePathFormat" => "/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔名格式 */
"fileUrlPrefix" => "", /* 檔案訪問路徑字首 */
"fileMaxSize" => 51200000, /* 上傳大小限制,單位B,預設50MB */
"fileAllowFiles" => [
".png", ".jpg", ".jpeg", ".gif", ".bmp",
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
], /* 上傳檔案格式顯示 */
/* 列出指定目錄下的圖片 */
"imageManagerActionName" => "listimage", /* 執行圖片管理的action名稱 */
"imageManagerListPath" => "/ueditor/php/upload/image/", /* 指定要列出圖片的目錄 */
"imageManagerListSize" => 20, /* 每次列出檔案數量 */
"imageManagerUrlPrefix" => "", /* 圖片訪問路徑字首 */
"imageManagerInsertAlign" => "none", /* 插入的圖片浮動方式 */
"imageManagerAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的檔案型別 */
/* 列出指定目錄下的檔案 */
"fileManagerActionName" => "listfile", /* 執行檔案管理的action名稱 */
"fileManagerListPath" => "/ueditor/php/upload/file/", /* 指定要列出檔案的目錄 */
"fileManagerUrlPrefix" => "", /* 檔案訪問路徑字首 */
"fileManagerListSize" => 20, /* 每次列出檔案數量 */
"fileManagerAllowFiles" => [
".png", ".jpg", ".jpeg", ".gif", ".bmp",
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
] /* 列出的檔案型別 */
];
以上兩個檔案目錄結果如下:
app/extend/ueditor/
./UeUpload.php
./config.php
通過上面的操作就可以完成所有的上傳操作,這裡沒有處理截圖,我把截圖功能去掉了。
如果要關閉儲存遠端圖片的功能,請在引入ueditor.confg.js檔案時找到: cateRemoteImageEnable: 設定為false即可。
自動儲存遠端圖片的功能是在複製別的網頁內容時裡面的域名不在配置的白名單裡(config.json[我這裡改成了動態的config.php])就會自動執行下載操作。然後進行替換後原來的URL。
詳見: https://blog.csdn.net/asdz1989253jm/article/details/44673847
到此就完成了,不過檔案列表這個沒有做,有興趣的可以參考Ueditor給的phpDemo來處理檔案列表就可以了。因為我們的專案開發中要將附件寫入資料庫記錄中,所以不是讀的檔案列表。