提到CKeditor、CKfinder,大家也许有些陌生,但提到FCKeditor,一定大名鼎鼎了。CKeditor与CKfinder就是它的新版本。
In 2009, we decided to rename the editor, bringing to light the next generation of our software: CKEditor 3.0.
需要注意的是新版本的CKeditor是不能上传和管理文件的,如果需要上传、管理文件需要安装它的姊妹产品:CKfinder。
不过貌似CKfinder是需要授权许可的(好像我在上传文件时好像看到一段话,大概意思是说你正使用的CKfinder体验版本,点击获取一个授权)。
下面说说初次使用容易遇到的问题:
一、配置:
你可以使用客户端JavaScript脚本以及你喜欢的服务器端语言(比如我这里用的PHP)来部署和配置它。
比如通过JavaScript方式来调用CKeditor编辑器及CKfinder:
01
02
{artContent}
03
04
05
06
//
07
if (typeof CKEDITOR =='undefined') {
08
document.write('加载CKEditor失败');
09
}
10
else {
11
var editor = CKEDITOR.replace('content',
12
{
13
fullPage :true
14
});
15
//ckfinder总目录的相对路径.
16
CKFinder.setupCKEditor(editor,'/ckfinder/' )
17
}
18
//]]>
19
加载CKEditor失败
通过PHP方式调用编辑器:
01
//配置CKeditor
02
require("public/ckeditor/ckeditor.php");
03
$CKEditor =new CKEditor();
04
$CKEditor->returnOutput = true;
05
$CKEditor->basePath ="public/ckeditor/";
06
$CKEditor->config['width'] = 600;
07
$CKEditor->config['toolbar'] =array(
08
array('Source','-','Undo','Redo','Find','Replace','-','Bold','TextColor','BGColor','Italic','Underline','Strike','SelectAll','RemoveFormat'),
09
//'/',
10
array('Image','Flash','Table','Rule','Link','Unlink','Anchor' ),
11
array('JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','Subscript','Superscript','OrderedList','UnorderedList','Outdent','Indent','FitWindow','-'),
12
13
);
14
$config['skin'] ='office2003';
15
//配置CKfinder
16
require_once 'public/ckfinder/ckfinder.php' ;
17
$ckeditor =new CKEditor( ) ;
18
$ckeditor->basePath ='public/ckeditor/';
19
CKFinder::SetupCKEditor($CKEditor,'/public/ckfinder/') ;
20
21
$initialValue ='被编辑内容';
22
$strEditor =$CKEditor->editor("content",$initialValue);
23
echo $strEditor;
二、因为安全原因,文件不可浏览. 请联系系统管理员并检查CKFinder配置文件.
CKeditor安装CKfinder之后直接上传文件会出现这个错误提示,原因是CKfinder有一个认证检测函数CheckAuthentication,该函数内容只有一行:return false;,大家在这里添加自己的验证方式。
编辑:CKfinder\config.php,找到function CheckAuthentication()一行,将下面的return false;改为你自己的验证函数即可。比如:
1
if(isset($_SESSION['mySession'])){
2
return true;
3
}else {
4
return false;
5
}
当然,你也可以直接将原来的return false改为return true,不过这是一种危险的做法。
三、上传的有中文文件名的文件时会出现乱码并且编辑器无法显示上传文件。
CKfinder直接将文件以原文件名保存到服务器的,不知道官方有没提供更改保存文件名的配置方法(我没找到),所以直接更改PHP文件。
打开:ckfinder\core\connector\php\php5\CommandHandler\FileUpload.php
1
//找到下面这几行,大约在59-61行左右:
2
if ($sFileName !=$sUnsafeFileName) {
3
$iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
4
}
5
//以下两行解决中文乱码问题(重命名)
6
$sExtension=CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
7
$sFileName=date("Ymd")."_".date("His").".".$sExtension;
–EOF–