日期:2014-05-17  浏览次数:20413 次

PHP下fckeditor 2.6.6的使用和配置(完整版)

一、下载

1、首先去官网下载FCKeditor2.6.6 多国语言版(可以搜索“FCKeditor 2.6.6, released on 15 February 2010”)。下载地址: http://ckeditor.com/download。

二、精简

按照如下步骤删除其中一些不需要的测试文件:

1.只保留/fckeditor/目录下的fckconfig.js(配置文件)、fckeditor.js(js方式调用文件)、fckeditor.php(php方式调用文件)、fckeditor_php4.php(php4的调用文件)、fckeditor_php5.php(php5的调用文件)、fckstyles.xml(样式)、fcktemplates.xml(模板)文件和editor文件夹七个文件以外的所有文件;

2.删除目录/editor/_source(基本上,所有_开头的文件夹或文件都是可选的);

3.删除/editor/filemanager/connectors/(存放编辑器所支持的Web动态语言)下除了php目录的所有目录;

4.删除/editor/lang/(存放的是多语言配置文件)下的除了 en.js, zh.js, zh-cn.js三个文件的所有文件。

三、设置

1.更改默认语言和编程语言:

打开/fckeditor/fckconfig.js ;(千万注意这个文件是utf-8编码,我第一次编辑的时候保存成了ANSI格式结果出错了,找了好长时间原因)修改->

FCKConfig.AutoDetectLanguage =false;(使其不能根据系统语言自动检测加载相应的语言。)

var FCKConfig.DefaultLanguage = ‘zh-cn’ ;

var _FileBrowserLanguage = ‘php’ ;

var _QuickUploadLanguage = ‘php’ ;

2.开启文件上传的功能:

配置editor\filemanager\connectors\php\config.php

将$Config['Enabled'] = false ;改为$Config['Enabled'] = true ;

更改$Config['UserFilesPath'] = ‘/userfiles/’ ;为你的上传目录(注意:这个目录要存在——自己创建好);

注意:这个目录是相对于主目录的。 也就是说,这个目录是相对于根目录的,注意,如果你在本机上测试,那么,这个根目录就是 http://localhost 。

四、调用

可以按下面的例子在php(例子中的PHP文件放在网站的子目录中)中调用fckeditor编辑器:

include(”../fckeditor/fckeditor.php”);??????? // 包含fckeditor类,fckeditor目录放在网站根目录下

$BasePath = “/fckeditor/”;??????????? // 编辑器路径

$oFCKeditor = new FCKeditor(’CreMer’);??? // 创建一个fckeditor对象,表单的名称为CreMer

$oFCKeditor->BasePath? = $BasePath;

$oFCKeditor->Value? = ‘test’;??????? // 设置表单初始值

// 还可设置以下部分(“=”包含部分),并非必须:

//==================================================================================//

$oFCKeditor->Width = ‘800′;??????????? // 编辑器宽度,类中有默认值,如果不想修改可不管此项

$oFCKeditor->Height= ‘300′;??????????? // 同width,此处为高$oFCKeditor->ToolbarSet

$oFCKeditor->ToolbarSet = ‘Basic’;??????? // 默认编辑器工具栏有Basic(基本工具)和Default(所有工具)两种选择,另外还可以自己建立工具栏

$oFCKeditor->Config['SkinPath'] = ‘/fckeditor/editor/skins/silver/’;??????? // 设置编辑器皮肤

//==================================================================================//

$oFCKeditor->Create();??????????? // 调用类中方法,必须

用$_POST['CreMer']就能获取文本框里面的值。

说明:

//包含fckeditor类

include(”../fckeditor/fckeditor.php”) ;

//设置编辑器路径

$sBasePath = “fckeditor/”;

//创建一个Fckeditor,表单的txtarea名称为content

$oFCKeditor = new FCKeditor(’content’) ;

$oFCKeditor->BasePath = $sBasePath ;

//设置表单初始值

$oFCKeditor->Value = ‘This is some <strong>sample text</strong>’ ;

$oFCKeditor->Create() ;