我希望在我的路径中有一个动态值,其中包含一个位于public_html以外的目录中的文件。当我测试
echo dirname(__FILE__);
我得到以下结果:
/home/domain/subdomain/mydir
与
相同/home/domain/public_html/mydir
这是我的开发服务器,网址为:subdomain.domain.com/mydir/file1
我想要包含的文件位于
/home/domain/include/anotherdir/file2
我的生产服务器具有不同的域,并且不使用子域: anotherdomain.com/mydir/file1 ,其解析为:
/home/anotherdomain/mydir/file1
有没有办法在不触及服务器设置的情况下使用PHP完成此动态路径?
答案 0 :(得分:1)
if(!defined('MYHOMEROOT'))
{
define('MYHOMEROOT',realpath(dirname(__FILE__).'/../../../'));
}
include(MYHOMEROOT.'/mydir1/file.php');
以上,请将'/../../../'
更改为" ../"你需要后退的路径
您可以通过
$testpath=realpath(dirname(__FILE__).'/../../../');
echo $testpath;
以上假设Linux 谢谢,