如何为fckeditor设置图像路径?

时间:2009-06-08 08:56:11

标签: fckeditor

我正在使用fckeditor for PHP。我已经设置了图像上传的绝对路径。我可以上传图片,但我无法使用上传的图片。任何人都可以帮我找到我的问题吗?

以下是我在config.php文件中更改的代码:

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

// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$Config['UserFilesAbsolutePath'] = '/var/www/host/mysite//userfiles/' ;

5 个答案:

答案 0 :(得分:4)

我在Google上搜索了一整天后才解决了这个令人沮丧的问题。

解决方案是here。寻找:

  

返回完整网址

     

您可以配置文件浏览器以返回FCKeditor的完整URL,例如“http://www.example.com/userfiles/”,而不是绝对URL,例如“/ userfiles /”。为此,您必须配置连接器,结合UserFilesPath和UserFilesAbsolutePath设置:

     
      
  • UserFilesPath:此处包含用户文件目录的完整URL。例如,将其设置为“http://www.example.com/userfiles/”。

  •   
  • UserFilesAbsolutePath:此处包含到达上述URL目录的服务器路径。例如,在Windows环境中,您可以使用类似“C:/ inetpub / mysite / userfiles /”的内容,而在Linux上则类似“/ usr / me / public_html / mysite / userfiles /".

    < / LI>   
     

只需将上述设置调整为安装值,文件浏览器就会开始将完整的网址返回给编辑器。

答案 1 :(得分:2)

对于您的localhost:

$Config['UserFilesPath'] = 'http://localhost/mywebsite/userfiles/' ;
$Config['UserFilesAbsolutePath'] = 'C:\\wamp\www\\mywebsite\\userfiles\\' ;

并且为了从那里获取图像,请使用:

$path = 'http://localhost/mywebsite/userfiles/image/myimage.jpg';

现在,对于您的网络服务器:

    $Config['UserFilesPath'] = 'http://localhost/mywebsite/userfiles/' ; // if your webserver named localhost as mine
$Config['UserFilesAbsolutePath'] = '/var/www/vhosts/mywebsite.com/httpdocs/' ;

并且图像路径保持与上面相同。

答案 2 :(得分:1)

检查文件夹的权限

答案 3 :(得分:0)

完整主题:FCK编辑器2.x:使用单个FCKeditor在不同文件夹中的文件/图像/视频上传,通过使$ Config [&#39; UserFilesPath&#39;]完全动态化安全的方式

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

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

a)追求全球$ Config;和$ Config [&#39;启用&#39;] = 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");
}

N.B。:这里,$ _SESSION [&#39; SESSION_SERVER_RELATIVEPATH&#39;]:与webroot对应的项目的相对文件夹路径;应该像&#34; / project / folder / path /&#34;并将此会话变量设置在会话开始的项目的公共文件中。并且应该有一个配置/ configuration.php作为项目中的配置文件。如果它的名称或路径不同,则必须在此处放置相应的路径而不是配置/配置.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");
}

请阅读N.B.在前一点结束时,即点(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");
}

请阅读N.B.在第(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 [&#39; UserFilesPath&#39;]。在我的bluehost linux服务器中,因为它们是项目根文件夹之间的文件夹用户权限冲突(0755权限)及其下的userfiles文件夹和userfiles下的子文件夹(根据FCKeditor编码应为0777),因此不允许上传这些文件夹中的文件。因此,我在服务器webroot(项目根文件夹之外)创建了一个文件夹userfiles,并将权限设置为0777,使用$ config设置的代码:

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

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

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

请注意,您可以将现有的$ Config [&#39; UserFilesPath&#39;] =&#39; / userfiles /&#39; ;在此文件中,通过替换或简单注释掉它是否存在于文件的其他位置。

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

搜索此行:var sConnUrl = GetUrlParam(&#39; Connector&#39;);

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

var param_project_to_fck = GetUrlParam( 'param_project_to_fck' ) ; 

现在,搜索此行:sUrl + =&#39;&amp; CurrentFolder =&#39; + 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-&gt; 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())

你已经完成了。

答案 4 :(得分:0)

UserFilesPath:此处包含用户文件目录的完整URL。例如,将其设置为“http://www.example.com/userfiles/”。