2012-04-18 106 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/")) 

然後您就完成了。