应该不会出现你说的情况include实际上相当于在此位置添加了include指定的文件内容

解决方案 »

  1.   

    会阿,比如说目录结构是:
    /class/class1.inc.php
    /db/db1.inc.php
    /test.phpclass1.inc.php有这样的语句:include("../db/db1.inc.php"),执行class1.inc.php是没有错的。
    test.php有这样的语句:include("./class/class1.inc.php"),这时候执行test.php就会出现找不到db1.inc.php的错误阿。
      

  2.   

    楼上两位都没有理解他的意思:以下是目录树:./
       |- index.php (需要 ./classes/HelloWorld.class.php 和 ./includes/global.php)
       |- ./classes
          |- HelloWorld.class.php
          |- DBMySQL.class.php
       |- ./includes
          |- global.php (而在这里又 include 了 ./classes/DBMySQL.class.php)那么 index.php 里面:<?php
      include("./global.php");
    ?>而 global.php 里面:
    <?php
      // include("./../classes/DBMySQL.class.php"); !! 这里出错,因为当 global.php 被 include 到 index.php 的时候,所在的目录是根目录(./),所以此时所指的(./../classes)就是上层目录了。不行
      include("./classes/DBMySQL.class.php"); // 这样就可以了。
    ?>但是你说到的其他目录引用 global.php 的时候,就出错是不是?
    例如有个 ./admin/admin.php 要 include 这个 global.php,所以你要更改当前目录。<?php
    //: admin/admin.php
    chdir('./../'); // 转到上层目录,此时跟 index.php 引用 global.php 一样,不会混淆。
    include('./include/global.php'); // 这里能看清楚吧?
    //:~
    ?>
      

  3.   

    楼上的虽然说可以解决问题,可是在每个页面都这样是不是有点麻烦啊?如果是这样我在每个页面定义一个常量WWW_ROOT,以后包含文件的时候就用include(WWW_ROOT."/db/db1.inc.php")也可以解决问题,就是觉得这样解决有点麻烦。
      

  4.   

    要说加一个目录转换或者一个目录定义都麻烦,就没辙啦。要说你的目录组织得好,就不会出现太多这种嵌套啦。GOOD LUCK。
      

  5.   

    这只能说是你的文件组织有问题
    1、
    /db/db1.inc.php
    应该也是类,同样应放在/class中
    引用时只需include 'db1.inc.php';2、在类中嵌入与类本身没多大关系的文件是不可取的,这使得类失去通用性
    如果/class/class1.inc.php中确实需要/db/db1.inc.php
    也应该在test.php中
    include 'db/db1.inc.php';
    include 'class/class1.inc.php';
      

  6.   

    include("./class/class1.inc.php"),
    改成
    include("class/class1.inc.php"),
    可以吗
      

  7.   

    会阿,比如说目录结构是:
    /class/class1.inc.php
    /db/db1.inc.php
    /test.phpclass1.inc.php 中include(dirname(__FILE__)."/../db/db1.inc.php"),
    test.php中:include(dirname(__FILE__)."/class/class1.inc.php"),使用dir(__FILE__)来取得当前文件的绝对路径,再根据当前文件的路径进行包含