繁体   English   中英

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

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

我正在为我的FCKeditor使用ASP.NET二进制文件,并且需要在同一页面上插入两个编辑器。 上传的图像/浏览需要转到两个不同的目录,如何从代码隐藏中执行此操作?

我知道路径上传的文件是在设置config.ascx与-file UserFilesPath设置,但我不能找到一种方法来覆盖从我的这个值aspx.cs文件。

此外,我发现(冲突的)文档说明可以设置Session["FCKeditor:UserFilesPath"] ,但我不喜欢将usercontrol特定信息放在全局会话变量中。

首先,您需要将用户身份信息分配到会话[“UserInfo”]

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

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

哦,亲爱的,经过多次努力,我能得到的是:

fckEditor1.Config

属性。 尝试为要配置的编辑器设置它:

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

这可能会奏效。 至少它对我有用。

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

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

完整主题:FCK编辑器2.x:使用单个FCKeditor在不同文件夹中为不同的应用程序上传文件/图像/视频,使$ Config ['UserFilesPath']以安全的方式完全动态

它可以通过多种方式完成。 我正在解释一个过程,我根据我的php应用程序的代码结构应用了它。 我为不同的应用程序遵循相同的代码结构/框架,每个应用程序作为我的服务器中的子文件夹。 因此,逻辑上需要使用一个FCKeditor并以某种方式对其进行配置,以便它适用于所有应用程序。 FCKeditor的内容部分没问题。 它可以通过单个FCKeditor组件轻松地由不同的应用程序或项目重用。 但问题出现在文件上传上,如图像,视频或任何其他文档。 为了使其适用于不同的项目,必须将文件上载到不同项目的separe文件夹中。 为此,$ Config ['UserFilesPath']必须配置动态文件夹路径,表示每个项目的不同文件夹路径,但在同一位置调用相同的FCKeditor组件。 我一步一步地解释了一些不同的过程。 FCKeditor版本2.5.1和VersionBuild 17566对我很有用,我希望它们也可以为其他人工作。 如果它不适用于其他开发人员,那么他们可能需要根据他们的项目代码结构和文件夹写入权限以及FCKeditor版本在这些过程中进行一些调整。

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

a)追求全球$ Config; 和$ Config ['Enabled'] = false; 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");
}

注意:这里,$ _SESSION ['SESSION_SERVER_RELATIVEPATH']:与webroot对应的项目的相对文件夹路径; 应该像“/ project / folder / path /”并将此会话变量设置在会话开始的项目中的公共文件中。 并且应该有一个配置/ configuration.php作为项目中的配置文件。 如果它的名称或路径不同,则必须在此处放置相应的路径而不是配置/ configuration.php

ii)如果希望将单个FCKeditor组件用于表示为不同子文件夹的不同项目,并使用会话相关的安全方式(假设不同项目的session_name不同,则在单个服务器中区分它们的会话)。 但是如果项目表示为子域或不同的域,那么它将不起作用,然后必须使用会话独立的方式(iii)提供(虽然它是不安全的)。 放置此代码:

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");
}

请在上一点结束时阅读NB,即点(i)

iii)如果想要为不同的项目使用单个FCKeditor组件,则表示不同的子文件夹以及子域或域(尽管它不是完全安全的)。 放置此代码:

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");
}

请在结束时阅读NB(i)

b)现在,对于您选择的任何案例,请找到此代码:

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

并替换以下代码:

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;

这里$ SERVER_RELATIVEPATH是相对路径,必须在之前包含的项目配置文件中设置。

在这里你可以使用$ file_upload_relative_path变量在任何其他动态文件夹路径中设置$ Config ['UserFilesPath']。在我的bluehost linux服务器中,因为它们是项目根文件夹(0755权限)和userfiles文件夹之间的文件夹用户权限冲突在它下面和用户文件下的子文件夹(根据FCKeditor编码应该是0777),所以它不允许在这些文件夹中上传文件。 因此,我在服务器webroot(项目根文件夹之外)创建了一个文件夹userfiles,并将权限设置为0777,使用$ config设置的代码:

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

但是,如果在您的案例中项目的子文件夹中的写权限没有问题,那么您可以使用上一行(在前面的代码段中注释掉):

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

记住它,你谴责现有的$ Config ['UserFilesPath'] ='/ userfiles /'; 在此文件中,通过替换或简单注释掉它是否存在于文件的其他位置。

2)如果您选择1)(a)(ii)或(iii)方法,则打开
(a)fckeditor \\ editor \\ filemanager \\ browser \\ default \\ browser.html文件。

搜索这一行:var sConnUrl = GetUrlParam('Connector');

将这些命令放在该行之后:

var param_project_to_fck = GetUrlParam( 'param_project_to_fck' ) ; 

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

在该行之后放置此命令:

sUrl += '&param_project_to_fck=' + param_project_to_fck ; 

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

搜索这一行(它应该在SetCurrentFolder()函数中):

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

在该行之后放置此命令:

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

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)现在,如果您选择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)如果你选择1)(a)(ii)方法,那么在上面的代码段中,只需用以下代码替换所有文本:base64_encode($ SERVER_RELATIVEPATH):base64_encode(session_name())

你完成了。

暂无
暂无

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

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