我需要包含一个配置文件中的路径,该路径位于其他目录中的一个目录上或几个目录下。
我的配置文件有一个类似如下的函数:
$execute_path = getcwd() . "/execute.php";execute.php文件与配置文件驻留在相同的目录中,这使得它没有问题,输出将变成:
public-html/config-directory/execute.php现在,如果在原始目录之外的目录中使用相同的函数,它会将getcwd()函数视为该目录中的函数。
例如,如果从目录public-html/one/two/three/somefile.php调用它,如下所示:
<?php
include(pathto/config.php)
echo $execute_path;
?>输出将变为publichtml/one/two/three/execute.php,而不是保持为publichtml/config-directory/execute.php
我如何才能在这里实现我想要的?很抱歉给你这么长的解释。谢谢。
发布于 2012-04-28 00:54:19
包括可能非常棘手,为什么我的建议是
//config.php
define("SITE_PATH", "public-html/config-directory");
//execute.php
$execute_path =SITE_PATH . "/execute.php";
//run.php
include_once 'config.php';
include_once 'execute.php';
echo $execute_path;https://stackoverflow.com/questions/10354739
复制相似问题