2012-04-18 111 views
2

我正在使用CKEditor与KCFinder - 我想要基于动态值的个人上传文件。KCFinder与CKEditor - 为上传文件设置动态文件夹

我想动态更改用户可以上传基于会话价值一旦被登录的文件夹。

一旦我登录想限制用户可以通过访问该文件夹KCFinder插件 所以如..

User abc their path would be abc/images 
User foo their path would be foo/images 
User abc cannot see foo's images & vice-versa 
+1

http://cksource.com/forums/viewtopic.php?f=6&t=7115 – SativaNL 2012-04-18 14:44:23

回答

5

我有同样的问题,更糟糕的是这取决于谁登录,管理员或普通会员。

授予我将它纳入TinyMCE的,但我认为,原则都是一样的

这里是我的解决问题的办法

我的文件夹结构

/my_uploads/media 

/my_uploads/media/member_folder 
  1. 初始化的PHP在config.php文件顶部的会话

    session_启动()

  2. 编辑 '类型'=>数组和注释所有不同 '类型'

  3. 添加以下 '类型' 到阵列

    $ _SESSION [” fold_type'] => “* IMG SWF FLV AVI MPG MPEG MOV QT ASF WMV RM”,

  4. 保存您的config.php文件

  5. 打开ÿ在那里你初始化你的编辑和调用KCFinder

  6. 初始化你的编辑之前我们的应用程序页面,添加以下代码行声明的各种KCFinder变量

    $_SESSION['KCFINDER'] = array(); 
    $_SESSION['KCFINDER']['disabled'] = false; // Activate the uploader, 
    $_SESSION['KCFINDER']['uploadURL'] = "/uploads"; 
    $_SESSION['fold_type'] = "media"; 
    

$_SESSION['KCFINDER'] = array(); 
    $_SESSION['KCFINDER']['disabled'] = false; // Activate the uploader, 
    $_SESSION['KCFINDER']['uploadURL'] = "/my_uploads/media/Members"; 
    $_SESSION['fold_type'] = "member_account_number_pulled_from_secure_session_variable"; 

7休假你把这个叫做上传者的那一行;

file: '../tiny_mce/plugins/kcfinder/browse.php?opener=tinymce', 

Set upload folder dynamically for KCFinder

1

它可以通过多种方式来完成。我正在解释一个流程,我根据我的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 \芯\ uploader.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 fi文件/页面,很明显,改变了你的项目/应用程序对应的变量值。但请首先阅读注释,以决定应保留哪些线路以及应根据您的流程注释哪些内容:

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/")) 

然后您就完成了。