CKFinder file manager integration
This feature allows you to insert images as well as links to files into the rich-text editor content. It is a bridge between the CKEditor 5 WYSIWYG editor and the CKFinder file manager and uploader. CKFinder is a commercial application that was designed with CKEditor compatibility in mind. It is currently available as version 3.x for PHP, ASP.NET and Java and version 2.x for ASP and ColdFusion.
CKFinder is a commercial solution. This feature is enabled by default in all predefined builds for convenience, but the editor will still work properly without activating it.
This feature can be used in the rich-text editor in two different ways:
-
As a server-side connector only (demo). In this scenario, images which are dropped or pasted into the editor are uploaded to the CKFinder server-side connector running on your server.
-
As a server and client-side file manager integration (demo). Images dropped and pasted directly into the editor are uploaded to the server (just like in the first option).
But there are more cool features available, for instance:
- uploading using the full user interface,
- uploading multiple files at once,
- browsing previously uploaded images,
- editing images (cropping, resizing, etc.),
- organizing or deleting images.
Check out the CKFinder file manager website to learn more about the features you can use in your project.
# Demo
# Image upload only
This demo shows the integration where the file manager’s server connector handles the image upload only:
- Paste the image directly into the rich-text editor content and it will be automatically uploaded using the server-side connector.
- Use the “Insert image” button in the toolbar to insert an image.
CKEditor 5 offers multiple ways to include images in your rich content. You can choose whichever you find more comfortable and efficient for you needs.
To upload an image, you can paste it or drag and drop it into the editor.
Alternatively, use the toolbar button to insert an image selected from your disk.
# Full integration
This demo shows the full integration with the CKFinder file uploader:
- Paste the image directly into the rich-text editor content and it will be automatically uploaded using the server-side connector.
- Use the “Insert image or file” button in the toolbar to open the CKFinder file manager and insert an image or a link to any other file.
CKEditor 5 offers multiple ways to include images in your rich content. You can choose whichever you find more comfortable and efficient for you needs.
To upload an image, you can paste it or drag and drop it into the editor.
Alternatively, use the toolbar button to open the CKFinder file manager. Use the file manager's interface to insert an image or a link to a file. Thanks to CKFinder you can also edit images, organize them into folders or delete from the server.
# Configuration
The feature is configurable by using the config.ckfinder
object.
# Configuring the image upload only
This feature can upload images automatically to the server (e.g. when the image is dropped into the content) thanks to the CKFinder upload adapter. All it requires is the correct config.ckfinder.uploadUrl
path.
Assuming that the CKFinder PHP server-side connector is installed (available) under https://example.com/ckfinder/
, use the following quick upload command URL to enable the image upload:
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ CKFinder, ... ],
// Enable the "Insert image" button in the toolbar.
toolbar: [ 'uploadImage', ... ],
ckfinder: {
// Upload the images to the server using the CKFinder QuickUpload command.
uploadUrl: 'https://example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&responseType=json'
}
} )
.then( ... )
.catch( ... );
See the demo of the image upload only.
# Configuring the full integration
To use both the image upload functionality and the file manager user interface in your application, you must first load the CKFinder JavaScript library and then enable CKFinder integration in your rich-text editor instance.
The easiest way to load the CKFinder library is to include the <script>
tag loading the ckfinder.js
file first:
<script src="https://ckeditor.com/apps/ckfinder/3.5.0/ckfinder.js"></script>
Then:
- Make sure that the CKFinder plugin for CKEditor 5 is enabled. See the Installation section.
- In order to enable the automatic file upload to the server when an image is pasted or dropped into the editor content, remember to set the correct
config.ckfinder.uploadUrl
path. - In order to display the toolbar button that opens the CKFinder file manager UI allowing the users to choose the files on the server, make sure that
'ckfinder'
is present in yourconfig.toolbar
. - Additionally, you can use
config.ckfinder.options
to define CKFinder’s options. For example:- You can define
options.resourceType
to tell CKFinder the specified resource type can be browsed when the user clicks the button. - You can define
options.language
to set the UI language of CKFinder. By default it will be set to the UI language of the editor.
- You can define
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ CKFinder, ... ],
// Enable the CKFinder button in the toolbar.
toolbar: [ 'ckfinder', ... ]
ckfinder: {
// Upload the images to the server using the CKFinder QuickUpload command.
uploadUrl: 'https://example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images&responseType=json',
// Define the CKFinder configuration (if necessary).
options: {
resourceType: 'Images'
}
}
} )
.then( ... )
.catch( ... );
See the demo of the full integration.
# Configuring the opener
You can change the way CKFinder opens using the config.ckfinder.openerMethod
option.
By default, the file manager opens as a modal. To open it in a new “pop-up” window, set the configuration value to popup
:
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ CKFinder, ... ],
toolbar: [ 'ckfinder', ... ]
ckfinder: {
// Open the file manager in the pop-up window.
openerMethod: 'popup'
}
} )
.then( ... )
.catch( ... );
# Configuring allowed file types
The allowed file types that can be uploaded should actually be configured in two places:
- On the client side, in CKEditor 5, restricting image upload through the CKEditor 5 UI and commands.
- On the server side, in CKFinder, restricting the file formats that are accepted in CKFinder.
# Client-side configuration
Use the image.upload.types
configuration option to define the allowed image MIME types that can be uploaded to CKEditor 5.
By default, users are allowed to upload jpeg
, png
, gif
, bmp
, webp
and tiff
files, but you can customize this behavior to accept, for example, SVG files.
# Server-side configuration
Use the allowedExtensions
configuration option to define the file extension allowed to be uploaded with CKFinder for a particular resource type. Refer to the relevant server-side connector documentation to learn more.
# Installation
This feature is enabled by default in all predefined builds. The installation instructions are for developers interested in building their own, custom WYSIWYG editor.
To add this feature to your editor, install the @ckeditor/ckeditor5-ckfinder
package:
npm install --save @ckeditor/ckeditor5-ckfinder
Then add CKFinder
to your plugin list and configure the feature (when necessary). For instance:
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ CKFinder, ... ],
toolbar: [ 'ckfinder', 'uploadImage' ... ], // Depending on your preference.
ckfinder: {
// Feature configuration.
}
} )
.then( ... )
.catch( ... );
# Common API
The CKFinder
plugin registers:
-
The
'ckfinder'
UI button component. -
The
'ckfinder'
command implemented by theCKFinderCommand
.You can open CKFinder by executing the following code:
editor.execute( 'ckfinder' );
Additionally, in the “image upload only” integration, you can use the following button and command registered by the ImageUpload
plugin:
- The
'uploadImage'
UI button component. - The
'uploadImage'
command implemented by theUploadImageCommand
.
We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
# What’s next?
Check out the comprehensive Image upload overview to learn more about different ways of uploading images in CKEditor 5.
See the image feature guide to find out more about handling images in CKEditor 5.
# Contribute
The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-ckfinder.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.