Skip to content Skip to sidebar Skip to footer

Customize Ckfinder Paths Dynamically With Js, Can It Be Done?

I'm doing an administrative function to work with CKEditor v4.x and need a file/folder view, upload and selection tool. For the time being I'm using CKFinder as I'd like to avoid w

Solution 1:

In our CMS area we use CKFinder.setupCKEditor() and I was unable to pass variables or flags to the config file correctly.

So I simply went to where the 'IsAuthorized' flag is set (that allows access to use CKFinder in their CheckAuthentication() function), and I set two more session variables: 'ckfinder_baseDir' and 'ckfinder_baseUrl'.

*Note that I have a Config class that checks the enviroment, hence Config::isDev(). You can check it any way that makes sense for you.

$_SESSION['IsAuthorized'] = 1;
$_SESSION['ckfinder_baseUrl'] = Config::isDev() ? 'http://devurl.com/' : 'http://produrl.com';
$_SESSION['ckfinder_baseUrl'] = Config::isDev() ? '/path/to/dev/uploads/' : 'path/to/prod/uploads';

Then I simply use these flags when in the CKFinder config.php file.

$baseUrl = $_SESSION['ckfinder_baseUrl'];
$baseDir = $_SESSION['ckfinder_baseDir'];

Solution 2:

You can specify the parameter on the frontend side in the definition of the filebrowser button as following

{
  type: 'button',
  label:'Button for filebrowser',
  filebrowser: {
      action: 'Browse',
      params: {
      'id': '{someID}'
      }
 },

Solution 3:

With help from the discussion Customize baseUrl and baseDir in CKFinder I got close to the answer with Travis comment.

There is a way to call different server side settings for each instance of CKFinder by just using a GET parameter in the path to CKFinder. I set the id of the filebrowserpath

filebrowserBrowseUrl:'/ckfinder/ckfinder.html?id=testdir'

And then in the config.php:

if ($_GET['id'] && $_GET['id'] == "testdir") {
   $baseDir = $baseDir . 'testdir/';
   $baseUrl = $baseUrl . 'testdir/';
}

This way each instance of CKeditor can use different basePath and baseUrl settings, and also other specific config.

Solution 4:

in config.ascx in setConfig() method

string userName = string.Empty;
    if (HttpContext.Current != null)
        userName = HttpContext.Current.User.Identity.Name;
    elsethrownewException("User Name is not provided");
    BaseUrl = "~/Uploads/Users/" + userName + "/";

Post a Comment for "Customize Ckfinder Paths Dynamically With Js, Can It Be Done?"