0

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 writing a complete plugin by myself. However for the purpose I need to be able to switch baseDir and baseUrl dynamically.

I tried older code examples like

CKFinder.setupCKEditor( 
          editor, 
          { 
                 basePath: '/ckfinder/', 
                 baseUrl: 'http://www.example.com/mydirectory/', 
                 baseDir: '/mydirectory/' 
           } 
);

But this doesn't work. Apparently you need to set the paths by PHP (server side). As I'm having many CKEditor instances on one page, generated dynamically, and all should use different CKFinder paths it is a great deal of work if I need to change the path asynchronously through AJAX calls... I can of course see the security considerations by letting client side code control baseDir. For the record this application, and CKFinder, is only available after login by administrative people.

jtheman
  • 7,421
  • 3
  • 28
  • 39

4 Answers4

1

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}'
      }
 },
Ramzan Mahmood
  • 1,881
  • 2
  • 21
  • 46
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'];
Gurnzbot
  • 3,742
  • 7
  • 36
  • 55
0

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.

Community
  • 1
  • 1
jtheman
  • 7,421
  • 3
  • 28
  • 39
0

in config.ascx in setConfig() method

    string userName = string.Empty;
    if (HttpContext.Current != null)
        userName = HttpContext.Current.User.Identity.Name;
    else
    throw new Exception("User Name is not provided");
    BaseUrl = "~/Uploads/Users/" + userName + "/";
unos baghaii
  • 2,539
  • 4
  • 25
  • 42