在网站系统根目录下建一个siteroot文件,不管进入网站的那一级目录,dirname(__FILE__)得到的路径中肯定包含网站系统根目录的字串,通过递减访问目录,在每级目录下寻找siteroot文件,找到的话,此目录即为网站系统安装目录

function getroot()
{
    $siteroot = dirname(__FILE__);
    for(;;)
    {
        $tempdir = $siteroot;
        //echo $tempdir;
        str_replace('\\', '/', $tempdir);
        if(file_exists($siteroot."/siteroot"))//siteroot是放在网站根目录下的一个标记文件
        {
            return str_replace('\\', '/', $tempdir);
        }
        else
        $siteroot = dirname($siteroot);
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-10-21
  • 2021-08-12
猜你喜欢
  • 2021-08-19
  • 2021-06-16
  • 2021-06-26
  • 2022-12-23
  • 2021-08-20
  • 2021-07-14
  • 2021-09-09
相关资源
相似解决方案