ckeditor + ckfinder + php 的详细配置。

本文介绍如何简化CKEditor的界面配置,并整合CKFinder实现文件管理与上传功能。包括调整CKEditor工具栏布局、设置CKFinder路径及权限验证、配置上传文件名等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 让ckeditor的编辑界面更简单.

 

在ckeditor根目录中修改config.js

CKEDITOR.editorConfig = function( config )
{
	// Define changes to default configuration here. For example:
    config.language = 'zh-cn';
	// config.uiColor = '#AADC6E';

config.toolbar_Full = [
['Source'],
['Cut','Copy','Paste','PasteText','PasteFromWord',],
['Undo','Redo','-','Find','Replace']
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],'/',
['Format','Font','FontSize'],
['TextColor','BGColor'],
['Image','Flash','Link','HorizontalRule','Smiley','SpecialChar','PageBreak']
];

config.font_names='宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+ config.font_names;

};

 

 

2. php中配置ckfinder + editor

<?php
class Das_CKEditor {
  
  protected $ckeditor_path ; 
  protected $ckfinder_path ;
  protected $ckeditor_webpath;
  protected $ckfinder_webpath;
  protected $_content;

  public function __construct(){
    $this->ckeditor_path = APPLICATION_PATH . "/resources/scripts/ckeditor/";
    $this->ckfinder_path = APPLICATION_PATH . "/resources/scripts/ckfinder/";
    //echo $this->ckeditor_path;
    //d:\xampp\htdocs\etc.....

    $app_web_path = 'http://' .$_SERVER['SERVER_NAME'] . '' . $_SERVER['SCRIPT_NAME'];   
    $app_web_path = strtolower($app_web_path);   
    $app_web_path = str_replace(  "index.php" , "" , $app_web_path);

    $this->ckeditor_webpath = $app_web_path . "resources/scripts/ckeditor/";
    $this->ckfinder_webpath = $app_web_path . "resources/scripts/ckfinder/";    		
  }

  public function init($content = null)
  {
    require_once $this->ckeditor_path . "ckeditor.php";
    require_once $this->ckfinder_path . "ckfinder.php";
    $ckeditor = new CKEditor();
    $ckeditor->returnOutput = true;
    $ckeditor->basePath = $this->ckeditor_webpath;
    CKFinder::SetupCKEditor($ckeditor , $this->ckfinder_webpath);
	//die($this->_content);
    $contentarea = $ckeditor->editor("editor_content" ,$content);
    return $contentarea;
  }

  
   
}


 

3,配置ckfinder的真实地址与上传后的url的配置,在ckfinder的config.php中修改

 

function CheckAuthentication()
{
	return true;
}

// LicenseKey : Paste your license key here. If left blank, CKFinder will be
// fully functional, in demo mode.
$config['LicenseName'] = '';
$config['LicenseKey'] = '';


//$baseUrl = '../../../uploads/';
$baseUrl = 'http://www.name.com/xinxibaosong/uploads/';


$baseDir = "d:/webphp/xinxibaosong/uploads/";


 

4.上传后修改文件的名为随机数字和字符

 

在ckfinder/core/connector/php/php5/CommandHandler/FileUpload.php中加入

    public function mySetFileName() {
        $gettime = explode(' ', microtime());
        $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
        $rand = '';

        for ($x = 0; $x < 5; $x++) {
            $rand .= substr($string, mt_rand(0, strlen($string) - 1), 1);
        }

        return date("ymdHis") . substr($gettime[0], 2, 6) . $rand;
    }


完后修改63行左右的

 

        if ($sFileName != $sUnsafeFileName) {
          $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
        }


修改为:

        if ($sFileName != $sUnsafeFileName) {
          $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
        }

        $sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
        $sFileName = $this->mySetFileName() . '.' . $sExtension;



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值