网站根目录
webweb/aa   目录
web/aa/inc  目录web/aa 下有一文件 index.php内容如下:
<?php
include_once("./inc/inc.php");这样的化报错提供如下:
//Warning: include_once() [function.include-once]: Unable to access ./inc/inc.php
?>但修改index.php内容如下则正常:
<?php
include_once(dirname(__FILE__) . "/inc/inc.php");这样的化报错提供如下:
?>原来好好的,现在程序转换到新服务器上就出现上面的情况了,不可能每个文件都修改成dirname函数类似的请高手指点一下是什么原因引起的是环境问题?

解决方案 »

  1.   

    对, 很多项目避免这种路径的错误, 都定义一个常量来存放根路径define('ROOT_PATH', dirname(__FILE__));然后就,  include_once ROOT_PATH."/inc/inc.php";
      

  2.   

    几乎大部份知名的开源项目都这样做, dz,wd, wp等
      

  3.   

    关键是现在这种错误出现了如何处理啊?
    http://jk.0574bm.com/
    大家帮忙看一下,现在好多这样的,不可能一一修改,唉,麻烦啊
      

  4.   

    Warning: include_once() [function.include-once]: Unable to access ./inc/get_rank.php in D:\wwwroot\0574bm_Channel\jk\index.php on line 3上面已经说行很明确了, 是你的路径错误上级目录对下级目录路径不用改, 把下级访问上级的目录按1楼的方法打个比方, 
    D:\wwwroot\0574bm_Channel \a.php
    D:\wwwroot\0574bm_Channel \jk     \index.php
    D:\wwwroot\0574bm_Channel \jk     \bk         \b.php
    主根目录是这个0574bm_Channel, 如果是jk这样的下级目录页面index.php要访问上级目录a.php时, 用一楼的方法而要访问下级的b.php就直接include bk\b.php