我想我當初一定是腦子抽了才會選擇CKEditor5的 , 再簡潔好看的UI , 也不值得我踩的這些坑.
- 前方高能預警
CKEditor5的官方文檔并沒有給出較全的文檔,并且谷歌百度資料較少,多是英文,要想自定義或是修改什么東西比較困難,不推薦用.
食用方式:
html:
<textarea name="content" id="editor"></textarea>
js:
//加載文件,記得自定義路徑哦
<script src="__PUBLIC__/Vendor/ckeditor5/ckeditor.js"></script>
<script src="__PUBLIC__/Vendor/ckfinder/ckfinder.js"></script>
<script src="__PUBLIC__/Vendor/ckeditor5/zh-cn.js"></script>
<script>
$(function () {
ClassicEditor
.create( document.querySelector( '#editor' ) ,{
language: 'zh-cn', //設(shè)置中文
ckfinder: { //上傳文件
uploadUrl: '/Public/Vendor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json',
}
})
.catch( error => {
console.error( error );
} )
})
</script>
到這一步ueditor的界面應(yīng)該已經(jīng)喚起成功,但是看代碼會發(fā)現(xiàn),上傳文件需要用ckfinder,并且還需要在config.php中進行各種配置

我解決的方法是:
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
ini_set('display_errors', 0);
session_start(); //添加這一行代碼
//將authentication更改為以下代碼
$config['authentication'] = function () {
if (!$_SESSION['user']) {
return 0;
}
return 1;
};
上傳文件夾的更改:
$config['backends'][] = array(
'name' => 'default',
'adapter' => 'local',
'baseUrl' => '/Uploads/', //這里更改
// 'root' => '', // Can be used to explicitly set the CKFinder user files directory.
'chmodFiles' => 0777,
'chmodFolders' => 0755,
'filesystemEncoding' => 'UTF-8',
);
上傳文件重命名:
\ckfinder\core\connector\php\vendor\cksource\ckfinder\src\CKSource\CKFinder\Command\FileUpload.php
在這個文件中找到$fileName = $uploadedFile->getFilename(); 這就是拿到文件原命名的代碼了,找到這行代碼,我們就可以按自己的規(guī)則給他命名了.
$fileName = $uploadedFile->getFilename();
//文件重命名
$ext = substr(strrchr($fileName, '.'), 1);
$fileName = $_SESSION['user']['uid'].'_'.time().'.'.$ext;