Home  >  Article  >  Backend Development  >  CKEditor and CKFinder configuration in PHP_PHP tutorial

CKEditor and CKFinder configuration in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:49:251008browse

1. /ckeditor/config.js, configuration file. If you don’t want to write too much, you can directly write the default configuration (language, menu bar, width). If necessary, you can configure Baidu config

config.language = 'en';
config.skin = 'v2';
config.uiColor = '#AADC6E';
config.toolbar = 'Basic';
….
2. Most of the official demos like to use js to configure the editor area. Being used to writing php, I find it troublesome, so I have to look at the built-in php class.

require_once ROOTPATH ​​. "ckeditor/ckeditor.php";
$CKEditor = new CKEditor();
$CKEditor->returnOutput = true; //Set the output available variables
$CKEditor->basePath = '/ckeditor/';//Set path
$contentarea = $CKEditor->editor("content", $rs['contents']); //Generate a textarea
with name as content
echo $contentarea;
3. It needs to be uploaded, so I have to join ckfinder. Place ckfinder and ckeditor in the same directory.
Open /ckfinder/config.php, first set the first function CheckAuthentication(). This function needs to be written according to its own rules. Only when it returns true can upload files to the server be allowed. Of course, it is not recommended to write return true directly. This will leading to security issues. It is more convenient to use session to handle it.

session_start();
function CheckAuthentication(){
If(isset($_SESSION['UseEidtor']))
        return true;
else
                                      return false;
}
4. Upload file location: Also in /ckfinder/config.php, find $baseUrl. I always wanted to write a method to locate the path, but it was really difficult. Later I had to use sesssion. If there is a need to upload to a website. Different locations can be positioned using session.

if (isset($_SESSION['UseEidtor'])) {
 
Switch ($_SESSION['UseEidtor']) {
case 'Addr1':
$baseUrl = '/addr1/uploadfile/';
case 'Addr2':
                $baseUrl = '/addr2/upfiles/';
}
 
} else {
 
$baseUrl = '/upfiles/';
 
}
5. For the uploaded file name, ckfinder will name it according to the original name. In the case of Chinese, it may be garbled, so it is recommended to use date renaming. Open /ckfinder/core/connector/php/php5/CommandHandler/FileUpload.php and find < /p>

$sUnsafeFileName =CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(CKFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
Add

after

$sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sUnsafeFileName);
$sUnsafeFileName=date('YmdHis').'.'.$sExtension;
6. The last thing is to use ckfinder

require_once ROOTPATH ​​. "ckeditor/ckeditor.php";
require_once ROOTPATH ​​. 'ckfinder/ckfinder.php' ;
 
$CKEditor = new CKEditor();
$CKEditor->returnOutput = true;
$CKEditor->basePath = '/ckeditor/';

CKFinder::SetupCKEditor($CKEditor, '/ckfinder/') ;//Note that this is a relative path, relative to the root directory, absolute paths cannot be used

$contentarea = $CKEditor->editor("content", $rs['contents']);
The combination of the two is quite good, and the more important reason is that it is much safer.


Excerpted from Shunzi Network

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478342.htmlTechArticle1. /ckeditor/config.js, configuration file, if you don’t want to write too much, you can directly write the default configuration (Language, menu bar, width), if necessary, you can configure Baidu config config.language =...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn