2011-12-14 100 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)不存在,它會在你上傳文件創建它。