CKEditor Integration

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

PHP

As of CKFinder 1.4.2 and CKEditor 3.1 it is possible to integrate CKFinder with CKEditor using PHP API.

SetupCKEditor

The static function SetupCKEditor() accepts four arguments:

SetupCKEditor( $editorObj [, $basePath, $imageType, $flashType] )
  • editorObj - CKEditor class instance.
  • basePath - The path where CKFinder is installed (optional, default value: "/ckfinder/").
  • imageType - Name of the resource type that should be used when CKFinder is launched from the Image dialog (optional).
  • flashType - Name of the resource type that should be used when CKFinder is launched from the Flash dialog (optional).

Example 1

$ckeditor = new CKEditor();
$ckeditor->basePath = '/ckeditor/';
CKFinder::SetupCKEditor($ckeditor, '/ckfinder/');
$ckeditor->editor('CKEditor1');

SetupCKEditorObject

The SetupCKEditorObject() method accepts three arguments:

SetupCKEditorObject( $editorObj [, $imageType, $flashType] )
  • editorObj - CKEditor class instance.
  • imageType - Name of the resource type that should be used when CKFinder is launched from the Image dialog (optional).
  • flashType - Name of the resource type that should be used when CKFinder is launched from the Flash dialog (optional).

Example 2

$ckeditor = new CKEditor();
$ckeditor->basePath = '/ckeditor/';
$ckfinder = new CKFinder();
$ckfinder->BasePath = '/ckfinder/'; // Note: BasePath property in CKfinder class starts with capital letter
$ckfinder->SetupCKEditorObject($ckeditor);
$ckeditor->editor('CKEditor1');

Manual integration

To instead configure CKEditor manually to use CKFinder, pass additional file browser configuration settings to the config property of the CKEditor instance:

Example 3

$ckeditor = new CKEditor();
$ckeditor->basePath = '/ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = '/ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = '/ckfinder/ckfinder.html?Type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = '/ckfinder/ckfinder.html?Type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('CKEditor1');

JavaScript

CKFinder 1.4 comes with built it APIs to easily integrate it with CKEditor.

CKFinder.SetupCKEditor

The SetupCKEditor() method accepts four arguments:

CKFinder.SetupCKEditor( editorObj, basePath[, imageType, flashType] )
  • editorObj - CKEditor instance, if the editorObj is null, then CKFinder will integrate with all CKEditor instances.
  • basePath - The path where CKFinder is installed (for example "/ckfinder/").
  • imageType - Name of the resource type that should be used when CKFinder is launched from the Image dialog.
  • flashType - Name of the resource type that should be used when CKFinder is launched from the Flash dialog.

Example 1

var editor = CKEDITOR.replace( 'editor1' );
 CKFinder.SetupCKEditor( editor, '/ckfinder/' );

It is also possible to pass an object with selected properties as the second argument:

Example 2

var editor = CKEDITOR.replace( 'editor1' );
 CKFinder.SetupCKEditor( editor, { BasePath : '/ckfinder/', RememberLastFolder : false } ) ;

...and below is example where we pass null as the first argument to integrate CKFinder with all CKEditor instances:

Example 3

CKFinder.SetupCKEditor( null, '/ckfinder/' );
 var editor = CKEDITOR.replace( 'editor1' );

Check the "_samples" folder for more examples.

Manual integration

To instead configure CKEditor manually to use CKFinder, pass some additional CKFinder configuration settings to the CKEditor instance:

Enabling CKFinder

CKEDITOR.replace( 'editor1',
 {
 	filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
 	filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?type=Images',
 	filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?type=Flash',
 	filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
 	filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
 	filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
 } 
 );

Just change "/ckfinder/" in the above URLs if you have CKFinder installed in a different place.

Changing size of CKFinder window

To change CKFinder window width/height use filebrowserWindowWidth / filebrowserWindowHeight settings:

CKEDITOR.replace( 'editor1',
 {
 	filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
 	filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?type=Images',
 	filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?type=Flash',
 	filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
 	filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
 	filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
 	filebrowserWindowWidth : '1000',
 	filebrowserWindowHeight : '700'
 } 
 );

It is possible to change the size of CKFinder window inside of specific dialog by adding it's name to the configuration setting, for example to change just the size of Image dialog, set the following property: filebrowserImageWindowWidth.

Specifying destination folder for Quick Uploads

The QuickUpload command is used when uploading files directly in the Upload tab (2) in CKEditor.

CKEditor Image Dialog.png

When configuring filebrowserUploadUrl settings, it is possible to point CKFinder to a subfolder of given resource type and upload files directly to this subfolder. In order to do this, add currentFolder attribute to the query string:

CKEDITOR.replace( 'editor1',
 {
 	filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
 	filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?type=Images',
 	filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?type=Flash',
 	filebrowserUploadUrl : 
 	   '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&currentFolder=/archive/',
 	filebrowserImageUploadUrl : 
 	   '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&currentFolder=/cars/',
 	filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
 } 
 );

Note: the specified folder must already exist on the server ("archive" and "cars" in this example).