2011-12-14 104 views
2

我正在使用CKEditor和KCFinder。除了一件事以外,一切都很好。如何更改KCFinder中图像的默认浏览目录?

我的默认上传网址为:

'uploadURL' => "/userfiles" 

比方说,我要上传图片。我点击CKEditor上传图片,然后点击浏览服务器选择一个已经上传的图片。问题是,CKEditor正在浏览/用户文件/图像,而不仅仅是我想要的/userfiles

我明白,这不是一个错误,只是它的设置方式,但我该如何改变它?

我没有找到http://kcfinder.sunhater.com

+0

http://www.xms-systems.co.uk/articles_read.php?a_id=77 – Stefan 2015-07-09 12:54:00

回答

1

什么我有同样的问题,直到我试图用会话参数如下(动态设置; http://kcfinder.sunhater.com/docs/install#dynamic):

 
$_SESSION['KCFINDER']['uploadURL'] = '/some_directory/some_subdir'; 
$_SESSION['KCFINDER']['uploadDir'] = '../some_directory/some_subdir'; 

的“的uploadURL”必须是指到“html”路径,即您的html标签可以识别的服务器根目录的绝对路径。举个例子,如果你的文件位于你的网络服务器的根目录中名为“图像”目录下,你将有:

 
$_SESSION['KCFINDER']['uploadURL'] = '/images'; 

的“uploadDir”必须引用包含的目录的相对路径你想访问的文件或者你的DISK根目录的绝对路径(例如:/ var/www/html/.....)。我认为最好从KCFinder安装路径的位置使用相对路径,因为这样它将是可移植的。 与上述相同的例子继续,并考虑到KCFinder安装在/ web_apps/kcfinder,那么你就会有这样的:

 
$_SESSION['KCFINDER']['uploadDir'] = '../../images'; 

希望这有助于!

+1

感谢您的回复Sudhir!我试过你推荐的东西,它仍然添加文件夹图像。 $ _SESSION ['KCFINDER'] ['uploadURL'] ='/ userfiles'; $ _SESSION ['KCFINDER'] ['uploadDir'] ='../../../userfiles'; KCFinder位于site.com/admin/ckeditor/kcfinder/ 如果我放入$ _SESSION ['KCFINDER'] ['uploadDir'] ='/ userfiles';它给了我一个错误“无法写入上传文件夹。/ userfiles” – Cris 2011-12-14 12:42:47

+1

我有同样的问题... – 2012-05-26 09:20:22

+0

我已经升级了这里的问题:https://github.com/sunhater/kcfinder/issues/144 – maartenmachiels 2016-06-06 19:00:49

2

我发现了一个更好的解决方法。

魔术的时候,在你的config.php文件,您可以定义发生:

'types' => array(
     // CKEditor & FCKEditor types 
     'files' => "disabled", 
     'flash' => "disabled", 
     'images' => "*img", 

     // TinyMCE types 
     'file' => "disabled", 
     'media' => "disabled", 
     'image' => "*img", 
    ), 

这是说KCfinder将创建一个“图像”目录和存储图像。我禁用了“文件”目录,因为我不允许用户上传文件。

如果您希望在根目录中使用它们,您可以添加一个''条目(空白)并指定它们可以上传的内容。在我的服务器中,我有:

'types' => array(
     '' => "*img", 
     // CKEditor & FCKEditor types 
     'files' => "disabled", 
     'flash' => "disabled" 
    ), 

它让我可以直接将图像文件上传到根文件夹。

0

的文件类型在CKEDITOR/FCKEDITOR自己的文件夹: 如果你想使用自己的文件夹的图片,文件只是在配置CKEDITOR/FCKEDITOR配置。JS

此行:

//KCFINDER 
CKEDITOR.editorConfig = function(config) { 
    config.filebrowserBrowseUrl = '/kcfinder-2.51/browse.php?type=file'; 
    config.filebrowserImageBrowseUrl = '/kcfinder-2.51/browse.php?type=image'; 
    config.filebrowserFlashBrowseUrl = '/kcfinder-2.51/browse.php?type=flash'; 
    config.filebrowserUploadUrl = '/kcfinder-2.51/upload.php?type=file'; 
    config.filebrowserImageUploadUrl = '/kcfinder-2.51/upload.php?type=image'; 
    config.filebrowserFlashUploadUrl = '/kcfinder-2.51/upload.php?type=flash'; 
}; 

例如,如果你想使用的图像为您的文件夹 “ImagesMyOwnFolder” ==>变线 config.filebrowserImageBrowseUrl = /kcfinder-2.51/browse.php?键入= ImagesMyOwnFolder';

希望这可以帮助那些想使用其他文件管理器的文件夹或现有文件夹,而这些文件夹已经存在并且不能移动。

0

它可以用很多方式完成。我正在解释一个流程,我根据我的php应用程序的代码结构应用了这个流程。我针对不同的应用程序遵循相同的代码结构/框架,每个应用程序都作为服务器中的一个子文件夹。所以,有理由需要使用KCfinder单个CKEditor并以某种方式对其进行配置,以便它适用于所有应用。 CKeditor的内容部分没问题。它可以轻松地被来自单个CKeditor组件的不同应用程序或项目重复使用。但问题出现在文件上传中,如图像,视频或任何其他文档。为使其适用于不同的项目,必须将文件上载到不同项目的分离文件夹中。对于$ _CONFIG ['uploadURL']必须通过动态文件夹路径配置,意味着每个项目的不同文件夹路径,但在相同位置调用相同的CKeditor KCfinder组件。我一步一步地解释一些不同的过程。 KCfinder版本2.51对我来说很好,我希望他们也能为其他人工作。如果它不适用于其他开发者,那么他们可能需要根据项目代码结构和文件夹写入权限以及CKeditor和KCfinder版本对这些过程进行一些调整。

1)在CKEDITOR \ filemanagers \ kcfinder_2_51 \ config.php文件

一)在$ _CONFIG数组定义,搜索此行 '已禁用'=>假,如果你发现任何与“残疾人更换'=> true, 在该文件的末尾放置以下代码。该代码是自我解释的逻辑和细节注释。的代码是:

//Code to assign $_CONFIG['uploadURL'] dynamic value: different for different projects or sites: added by Mrinal Nandi on 5 oct, 2013: start 
//session dependent dynamic $_CONFIG['uploadURL'] setting :start 

////session dependent secure method: only for single site setting: i.e. one CKeditor KCfinder for each one project domain or subdomain, not one CKeditor KCfinder for multiple project:start  
// session_start(); 
//if(isset($_SESSION['KCFINDER']['uploadURL']) && $_SESSION['KCFINDER']['uploadURL']!="") { //$_SESSION['SESSION_SERVER_RELATIVEPATH']: relative folder path of the project corresponding to the webroot; should be like "/project/folder/path/" //set this session variable in a common file in your project where the session started 
// $file_upload_relative_path=$_SESSION['KCFINDER']['uploadURL']; 
//} 
////session dependent secure method: only for single site setting: i.e. one CKeditor KCfinder for each one project domain or subdomain, not one CKeditor KCfinder for multiple project:start 


//Using a single CKeditor KCfinder component for different projects or sites (multisite): start 

//session dependent settings a single CKeditor KCfinder component for different projects or sites (multisite): start 
//Assuming different session_name for different projects, if represented as different sub-folders, but not work if represented as sub-domains or different domains 
//Secure and deny access for unauthorized users without any session, thus restrict access via direct link 
//but not work if projects represented as sub-domains or different domains, then have to use the session independent way provided bellow (though it is insecure), or have to implement some session related way as per the project flow and structure 

session_name(base64_decode($_REQUEST['param_project'])); 
session_start();  

if(isset($_SESSION['KCFINDER']['uploadURL']) && $_SESSION['KCFINDER']['uploadURL']!="") { //$_SESSION['SESSION_SERVER_RELATIVEPATH']: relative folder path of the project corresponding to the webroot; should be like "/project/folder/path/" //set this session variable in a common file in your project where the session started 
    $file_upload_relative_path=$_SESSION['KCFINDER']['uploadURL']; 

} 
//session dependent settings a single CKeditor KCfinder component for different projects or sites (multisite): end 



//session dependent dynamic $_CONFIG['uploadURL'] setting :end 

////session independent dynamic $_CONFIG['uploadURL'] setting: without using session :start 
//if(isset($_REQUEST['param_project']) && $_REQUEST['param_project']!=""){ //base64 encoded relative folder path for file upload in the project, corresponding to the webroot; should be like "/project/folder/file/upload/path/" before encoding 
// $file_upload_relative_path=base64_decode($_REQUEST['param_project']); 
// 
//} 
////session independent dynamic $_CONFIG['uploadURL'] setting: without using session :end 


if(isset($file_upload_relative_path) && trim($file_upload_relative_path)!=""){ 
    if(isset($_SESSION['KCFINDER']['uploadURL'])){ 
     $_CONFIG['disabled']=false; 
    } else if(is_dir($file_upload_relative_path)) { //to make it relatively secure so that hackers can not create any upload folder automatcally in the server, using a direct link and can not upload files there 
     $_CONFIG['disabled']=false; 
    } 
} 
// Path to user files relative to the document root. 
$_CONFIG['uploadURL']= $file_upload_relative_path; 
$_CONFIG['param_project'] = $_REQUEST['param_project']; 
//Using a single CKeditor KCfinder component for different projects or sites (multisite): end 

//Code to assign $_CONFIG['uploadURL'] dynamic value: different for different projects or sites: added by Mrinal Nandi on 5 oct, 2013: end 

2)在CKEditor的\ filemanagers \ kcfinder_2_51 \ JS \浏览器\ misc.js

搜索这一行:VAR数据= '?browse.php类型=' + encodeURIComponent方法( this.type)+'& lng ='+ this.lang;

与该行替换:

var data = 'browse.php?type=' + encodeURIComponent(this.type) + '&lng=' + this.lang + '&param_project=' + this.param_project; 

3)在CKEditor的\ filemanagers \ kcfinder_2_51 \ TPL \ tpl_javascript.php

搜索这一行:browser.type = “?型)>” ;

把这些命令该行之后:

browser.param_project = "<?php echo text::jsValue($this->config['param_project']) ?>"; 

4)在CKEditor的\ filemanagers \ kcfinder_2_51 \核心\载。PHP 搜索该行__construct()函数:

if (isset($this->config['_check4htaccess']) && 
    $this->config['_check4htaccess'] 
) { 
    $htaccess = "{$this->config['uploadDir']}/.htaccess"; 
    if (!file_exists($htaccess)) { 
     if ([email protected]_put_contents($htaccess, $this->get_htaccess())) 
      $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); 
    } else { 
     if (false === ($data = @file_get_contents($htaccess))) 
      $this->backMsg("Cannot read .htaccess"); 
     if (($data != $this->get_htaccess()) && [email protected]_put_contents($htaccess, $data)) 
      $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); 
    } 
} 

而且注释掉全断面

4)现在要显示CKEDITOR在你的项目,你必须把那些线相应的php文件/页面,显然会改变与您的项目/应用程序相对应的变量值。但请首先阅读注释,以决定应保留哪些线路以及应根据您的流程注释哪些内容:

include_once(Absolute/Folder/path/for/CKeditor/."ckeditor/ckeditor.php") ; 

//If you did not want a session oriented way, cooment out the session related lines 
$_SESSION['KCFINDER'] = array();          
$_SESSION['KCFINDER']['uploadURL']=$SERVER_RELATIVEPATH."userfiles/"; 

$CKEditor = new CKEditor(); 
$CKEditor->basePath = HTTP_COMPONENTPATH."ckeditor_3.6.2/ckeditor/"; 

//$_SESSION['KCFINDER']['uploadURL']="/userfiles/fashion_qr/"; 

$CKEditor->config["filebrowserBrowseUrl"] = ($CKEditor->basePath)."filemanagers/kcfinder_2_51/browse.php?type=files&param_project=".base64_encode(session_name()); 
$CKEditor->config["filebrowserImageBrowseUrl"] = ($CKEditor->basePath)."filemanagers/kcfinder_2_51/browse.php?type=images&param_project=".base64_encode(session_name()); 
$CKEditor->config["filebrowserFlashBrowseUrl"] = ($CKEditor->basePath)."filemanagers/kcfinder_2_51/browse.php?type=flash&param_project=".base64_encode(session_name()); 

$CKEditor->editor("Content", getIfSet($data['Content'])); 
//if you did not want a session oriented way, then in the above code code segment, just replace all the texts: base64_encode(session_name()) with this one: base64_encode(session_name($SERVER_RELATIVEPATH."userfiles/")) 

然后您就完成了。

0

这是我的解决方案。 CKEditor的配置:

<?php $filesFolder = "topic123"; ?> 
CKEDITOR.replace('contentEditor', { 
    filebrowserBrowseUrl: '/public/plugins/ckfinder/ckfinder.html?type=<?=$filesFolder?>' 
}); 

我指定只有一个参数filebrowserBrowseUrl并通过了类型。现在,当您打开任何网址,图片或Flash对话框时,它将只显示一个目录。

然后在CKFinders config.php文件:

$config['backends'][] = array(
    'name'   => 'topic_files', 
    'adapter'  => 'local', 
    'baseUrl'  => '/data/topics/', 
    //'root'   => '', // Can be used to explicitly set the CKFinder user files directory. 
    'chmodFiles' => 0777, 
    'chmodFolders' => 0755, 
    'filesystemEncoding' => 'UTF-8', 
); 

if (!empty($_GET['type'])) { 
    //Folder for topics 
    if (preg_match("/^topic\d+$/", $_GET['type'])) { 
     $config['resourceTypes'][] = [ 
      'name'    => $_GET['type'], 
      'directory'   => $_GET['type'], 
      'maxSize'   => 0, 
      'allowedExtensions' => $allowedExtensions, 
      'deniedExtensions' => '', 
      'backend'   => 'topic_files' 
     ]; 
    } 
} 

如果文件夹(topic123)不存在,它会在你上传文件创建它。