Please note that the information contained in this blog post was written in 2013 and is about programming with code igniter., so some of the information may not be applicable today. However, the general principles and ideas presented are still relevant.
If you are using Codeignitor, CKFinder, and CKEditor, you may have the challenge of integrating the CKEditor and CKFinder systems into the Codeignitor framework. CKEditor is easy to set up inside Codeignitor by loading all of the ckeditor files/folders into the root directory, including the JS file, and configuring it like you would on any normal website. CKFinder is practically the same.
However, if you have multiple user accounts, and each user account needs to have its own folder to use with CKFinder, you need to create a new folder for each user. By default, CKFinder defaults to ckfinder/userfiles and works all internally. The challenge is to have a new folder (named the ID of the user) for each user.
To accomplish this, follow these steps:
- Set up a new folder in the main directory (the same directory that contains your Codeignitor index file). Name the folder “ckfinder_userfiles” and load it up to the server.
- Open the CKFinder config file. If you loaded your CKFinder folder into the server in the main directory, you can find the config file at the following location: /ckfinder/config.php
- Assuming you have a session saved using Codeignitor that is called “user_id,” you need to look for the area where the base_url is set up. Replace the base url parameter with the following code:
$session = unserialize($_COOKIE['ci_session']);
$user_id = $session['user_id'];
$baseUrl = '/ckfinder_userfiles/' . $user_id . '/';
This code will take the internal Codeignitor session and dig out the user_id and use that to build the base url. Now anytime that user is logged in (assuming the user_id is set as a session to their user id), then it will automatically default internally to the folder ckfinder_userfiles/theirid. CKFinder will create the folder automatically, and this restricts users across the board to only entering their one folder.
There are probably other solutions to this problem, but this specific solution is very effective and seemingly very secure. If you have any thoughts regarding this procedure or maybe things you have tried in your own implementations, feel free to comment.
Other archived posts can be found here.
The PHP manual can be found here.