本文介绍了用JS动态定制CKFinder路径,可以做吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个管理功能,使用CKEditor v4.x,需要一个文件/文件夹视图,上传和选择工具。目前我使用CKFinder,因为我想避免自己写一个完整的插件。然而为了这个目的,我需要能够动态切换baseDir和baseUrl。



我尝试过的代码示例如下:

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

但这不起作用。显然你需要通过PHP(服务器端)设置路径。因为我有一个页面上有许多CKEditor实例,动态生成,并且应该使用不同的CKFinder路径,如果我需要通过AJAX调用异步更改路径,这是一个很大的工作...我当然可以看到安全考虑通过让客户端代码控制baseDir。

解决方案

在讨论的帮助下我接近Travis的回答。



有一种方法可以通过在CKFinder的路径中使用GET参数为CKFinder的每个实例调用不同的服务器端设置。我设置了filebrowserpath的ID

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



然后在config.php中:

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

这样CKeditor的每个实例都可以使用不同的basePath和baseUrl设置,其他特定配置。


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.

解决方案

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.

这篇关于用JS动态定制CKFinder路径,可以做吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:58