简体   繁体   English

如何在FCKeditor中动态更改图像上载路径*

[英]How do I change image upload path *dynamically* in FCKeditor

I'm using the ASP.NET binary for my FCKeditor, and needs to insert two editors on the same page. 我正在为我的FCKeditor使用ASP.NET二进制文件,并且需要在同一页面上插入两个编辑器。 The uploaded images/browsing needs to go to two different directories, how do I do this from code-behind? 上传的图像/浏览需要转到两个不同的目录,如何从代码隐藏中执行此操作?

I know the path for uploaded files are set in the config.ascx -file with the UserFilesPath setting, but I can not find a way to override this value from my aspx.cs file. 我知道路径上传的文件是在设置config.ascx与-file UserFilesPath设置,但我不能找到一种方法来覆盖从我的这个值aspx.cs文件。

Also, I found (conflicting) documentation stating that Session["FCKeditor:UserFilesPath"] could be set, but I dont like putting usercontrol-specific information in a global session variable. 此外,我发现(冲突的)文档说明可以设置Session["FCKeditor:UserFilesPath"] ,但我不喜欢将usercontrol特定信息放在全局会话变量中。

first you need assign User Identity information into Session["UserInfo"] 首先,您需要将用户身份信息分配到会话[“UserInfo”]

then go to [fckeditor root folder]/filemanager/connector/aspx/config.ascx 然后转到[fckeditor root folder] /filemanager/connector/aspx/config.ascx

string Userfolder = Session["UserInfo"].ToString(); // URL path to user files. UserFilesPath = "~/Upload/" + Userfolder;

Oh dear, after much struggle only thing I'm able to get is: 哦,亲爱的,经过多次努力,我能得到的是:

fckEditor1.Config fckEditor1.Config

property. 属性。 Try setting it for the editor you want to configure: 尝试为要配置的编辑器设置它:

fckEditor1.Config["UserFilesPath"]="your path" fckEditor1.Config [“UserFilesPath”] =“你的路径”

This will probably works. 这可能会奏效。 At least it worked for me. 至少它对我有用。

Session["FCKeditor:UserFilesPath"] = "~/images/";

对不起,我认为你最好的办法是停止使用控件,而是使用javascript api。

Full Subject: FCK editor 2.x: File/image/video upload in different folders for different applications using a single FCKeditor, by making $Config['UserFilesPath'] fully dynamic in a secure way 完整主题:FCK编辑器2.x:使用单个FCKeditor在不同文件夹中为不同的应用程序上传文件/图像/视频,使$ Config ['UserFilesPath']以安全的方式完全动态

It can be done in many ways. 它可以通过多种方式完成。 I am explaining a process, which I applied as per my php applications' code structure. 我正在解释一个过程,我根据我的php应用程序的代码结构应用了它。 The same code structure/framework I followed for different applications, with each application as a sub-folder in my server. 我为不同的应用程序遵循相同的代码结构/框架,每个应用程序作为我的服务器中的子文件夹。 So, there is a logical need to use one single FCKeditor and configure it in some way, so that it work properly for all the applications. 因此,逻辑上需要使用一个FCKeditor并以某种方式对其进行配置,以便它适用于所有应用程序。 The content part of FCKeditor is ok. FCKeditor的内容部分没问题。 It can easily be reused by different applications or projects from a single FCKeditor component. 它可以通过单个FCKeditor组件轻松地由不同的应用程序或项目重用。 But the problem arises with file upload, like image, video or any other document. 但问题出现在文件上传上,如图像,视频或任何其他文档。 To make it applicable for different project, the files must be uploaded in separe folders for different projects. 为了使其适用于不同的项目,必须将文件上载到不同项目的separe文件夹中。 And for that $Config['UserFilesPath'] must by configured with dynamic folder path, means different folder path for each project, but calling the the same FCKeditor component in the same location. 为此,$ Config ['UserFilesPath']必须配置动态文件夹路径,表示每个项目的不同文件夹路径,但在同一位置调用相同的FCKeditor组件。 I am explaning some differnt process together in a step-by-step way. 我一步一步地解释了一些不同的过程。 Those worked for me fine with FCKeditor version 2.5.1 and VersionBuild 17566 and I hope they will work for others as well. FCKeditor版本2.5.1和VersionBuild 17566对我很有用,我希望它们也可以为其他人工作。 If it does not work for other developrs, then may be they need to make some tweaks in those process as per their project code structure and folder write permission as well as per the FCKeditor version. 如果它不适用于其他开发人员,那么他们可能需要根据他们的项目代码结构和文件夹写入权限以及FCKeditor版本在这些过程中进行一些调整。

1) In fckeditor\\editor\\filemanager\\connectors\\phpconfig.php file 1)在fckeditor \\ editor \\ filemanager \\ connectors \\ phpconfig.php文件中

a) Go after global $Config ; a)追求全球$ Config; and $Config['Enabled'] = false ; 和$ Config ['Enabled'] = false; i) There, if want a session dependent secure method: only for single site setting: ie one FCKeditor for each one project domain or subdomain, not one FCKeditor for multiple project then place this code: i)在那里,如果想要一个会话相关的安全方法:仅用于单个站点设置:即每个项目域或子域一个FCKeditor,而不是一个FCKeditor用于多个项目,然后放置此代码:

if(!isset($_SESSION)){
session_start(); 
}

if(isset($_SESSION['SESSION_SERVER_RELATIVEPATH']) && $_SESSION['SESSION_SERVER_RELATIVEPATH']!="") { 
$relative_path=$_SESSION['SESSION_SERVER_RELATIVEPATH']; 
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}

NB: Here, $_SESSION['SESSION_SERVER_RELATIVEPATH']: relative folder path of the project corresponding to the webroot; 注意:这里,$ _SESSION ['SESSION_SERVER_RELATIVEPATH']:与webroot对应的项目的相对文件夹路径; should be like "/project/folder/path/" and set this session variable in a common file in your project where the session started. 应该像“/ project / folder / path /”并将此会话变量设置在会话开始的项目中的公共文件中。 And there should be a configurations/configuration.php as the configuration file in your project. 并且应该有一个配置/ configuration.php作为项目中的配置文件。 If it's name or path is different you have to place the corresponding path here instead of configurations/configuration.php 如果它的名称或路径不同,则必须在此处放置相应的路径而不是配置/ configuration.php

ii) If want to use a single FCKeditor component for different projects represented as different sub-folders and with a session dependent secure way (Assuming different session_name for different projects, to differentiate their sessions in a single server). ii)如果希望将单个FCKeditor组件用于表示为不同子文件夹的不同项目,并使用会话相关的安全方式(假设不同项目的session_name不同,则在单个服务器中区分它们的会话)。 But it will not work if projects represented as sub-domains or different domains, then have to use the session independent way (iii) provided bellow (though it is insecure). 但是如果项目表示为子域或不同的域,那么它将不起作用,然后必须使用会话独立的方式(iii)提供(虽然它是不安全的)。 Place this code: 放置此代码:

if(!isset($_SESSION)){
session_name($_REQUEST['param_project_to_fck']); 
session_start(); 
}

if(isset($_SESSION['SESSION_SERVER_RELATIVEPATH']) && $_SESSION['SESSION_SERVER_RELATIVEPATH']!="") { 
$relative_path=$_SESSION['SESSION_SERVER_RELATIVEPATH']; 
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}

Please read NB at the end of previous point, ie point (i) 请在上一点结束时阅读NB,即点(i)

iii) If want to use a single FCKeditor component for different projects represented either different sub-folders as well as sub-domains or domains (though it is not fully secure). iii)如果想要为不同的项目使用单个FCKeditor组件,则表示不同的子文件夹以及子域或域(尽管它不是完全安全的)。 Place this code: 放置此代码:

if(isset($_REQUEST['param_project_to_fck']) && $_REQUEST['param_project_to_fck']!=""){ //base64 encoded relative folder path of the project corresponding to the webroot; should be like "/project/folder/path/" before encoding 
$relative_path=base64_decode($_REQUEST['param_project_to_fck']);
include_once($_SERVER['DOCUMENT_ROOT'].$relative_path."configurations/configuration.php");
}

Please read NB at the end of point (i) 请在结束时阅读NB(i)

b)Now after that for any case you selected, please find this code: b)现在,对于您选择的任何案例,请找到此代码:

// Path to user files relative to the document root.
$Config['UserFilesPath'] = '/userfiles/' ;

and replace the following code: 并替换以下代码:

if(isset($SERVER_RELATIVEPATH) &&  $SERVER_RELATIVEPATH==$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['Enabled'] = true ;
$file_upload_relative_path=$SERVER_RELATIVEPATH;
}else{
$Config['Enabled'] = false ;
exit();
}
// Path to user files relative to the document root.
//$Config['UserFilesPath'] = '/userfiles/' ;
//$Config['UserFilesPath'] = $file_upload_relative_path.'userfiles/' ;
$Config['UserFilesPath'] = '/userfiles'.$file_upload_relative_path;

Here $SERVER_RELATIVEPATH is the relative path and it must be set in your project's configuration file included previously. 这里$ SERVER_RELATIVEPATH是相对路径,必须在之前包含的项目配置文件中设置。

Here you can set the $Config['UserFilesPath'] with any other dynamic folder path using $file_upload_relative_path variable.In my bluehost linux server, as their was a folder user permission conflict between the project root folder (0755 permission) and the userfiles folder under it and subfolders under userfiles (should be 0777 as per FCKeditor coding), so it does not allow uploading files in those folders. 在这里你可以使用$ file_upload_relative_path变量在任何其他动态文件夹路径中设置$ Config ['UserFilesPath']。在我的bluehost linux服务器中,因为它们是项目根文件夹(0755权限)和userfiles文件夹之间的文件夹用户权限冲突在它下面和用户文件下的子文件夹(根据FCKeditor编码应该是0777),所以它不允许在这些文件夹中上传文件。 So, I created a folder userfiles at the server webroot (beyond the project root folder), and set the permission to 0777 to it, use the code for the $config setting as : 因此,我在服务器webroot(项目根文件夹之外)创建了一个文件夹userfiles,并将权限设置为0777,使用$ config设置的代码:

$Config['UserFilesPath'] = '/userfiles'.$file_upload_relative_path; 

But, if you have no problem with write permission in the project's subfolders in your case, then you can use the previous line (commented out in the previous code segment): 但是,如果在您的案例中项目的子文件夹中的写权限没有问题,那么您可以使用上一行(在前面的代码段中注释掉):

$Config['UserFilesPath'] = $file_upload_relative_path.'userfiles/' ;

Mind it, you mast comment out the existing $Config['UserFilesPath'] = '/userfiles/' ; 记住它,你谴责现有的$ Config ['UserFilesPath'] ='/ userfiles /'; in this file by either replacing or simply commenting out if it exist in other place of the file. 在此文件中,通过替换或简单注释掉它是否存在于文件的其他位置。

2) If you choose 1) (a) (ii) or (iii) method then open 2)如果您选择1)(a)(ii)或(iii)方法,则打开
(a) fckeditor\\editor\\filemanager\\browser\\default\\browser.html file. (a)fckeditor \\ editor \\ filemanager \\ browser \\ default \\ browser.html文件。

Search for this line: var sConnUrl = GetUrlParam( 'Connector' ) ; 搜索这一行:var sConnUrl = GetUrlParam('Connector');

Put these commands after that line: 将这些命令放在该行之后:

var param_project_to_fck = GetUrlParam( 'param_project_to_fck' ) ; 

Now, Search for this line: sUrl += '&CurrentFolder=' + encodeURIComponent( this.CurrentFolder ) ; 现在,搜索这一行:sUrl + ='&CurrentFolder ='+ encodeURIComponent(this.CurrentFolder);

Put this command after that line: 在该行之后放置此命令:

sUrl += '&param_project_to_fck=' + param_project_to_fck ; 

(b) Now, open ckeditor\\editor\\filemanager\\browser\\default\\frmupload.html file. (b)现在,打开ckeditor \\ editor \\ filemanager \\ browser \\ default \\ frmupload.html文件。

Search for this line (it should be in the SetCurrentFolder() function): 搜索这一行(它应该在SetCurrentFolder()函数中):

sUrl += '&CurrentFolder=' + encodeURIComponent( folderPath ) ;

Put this command after that line: 在该行之后放置此命令:

sUrl += '&param_project_to_fck='+window.parent.param_project_to_fck;

3) Now where you want to show the FCKeditor in your project, you have to put those lines first in the corresponding php file/page: 3)现在你要在项目中显示FCKeditor,你必须先将这些行放在相应的php文件/页面中:

include_once(Absolute/Folder/path/for/FCKeditor/."fckeditor/fckeditor.php") ; 
$oFCKeditor = new FCKeditor(Field_name_for_editor_content_area) ;
$oFCKeditor->BasePath = http_full_path_for_FCKeditor_location.'fckeditor/' ;
$oFCKeditor->Height = 400;
$oFCKeditor->Width = 600;
$oFCKeditor->Value =Your_desired_content_to_show_in_editor;
$oFCKeditor->Create() ; 

a) Now, if you choose 1) (a) (ii) or (iii) method then place the following code segment before that line: $oFCKeditor->Create() ; a)现在,如果您选择1)(a)(ii)或(iii)方法,则在该行之前放置以下代码段:$ oFCKeditor-> Create();

$oFCKeditor->Config["LinkBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Connector=../../connectors/php/connector.php&param_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);
$oFCKeditor->Config["ImageBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Type=Image&Connector=../../connectors/php/connector.php&param_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);
$oFCKeditor->Config["FlashBrowserURL"] = ($oFCKeditor->BasePath)."editor/filemanager/browser/default/browser.html?Type=Flash&Connector=../../connectors/php/connector.php&param_project_to_fck=".base64_encode($SERVER_RELATIVEPATH);

b) if you chose 1) (a) (ii) method, then in the above code code segment, just replace all the texts: base64_encode($SERVER_RELATIVEPATH) with this one: base64_encode(session_name()) b)如果你选择1)(a)(ii)方法,那么在上面的代码段中,只需用以下代码替换所有文本:base64_encode($ SERVER_RELATIVEPATH):base64_encode(session_name())

And you are done. 你完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM