PHP:包含和要求文件时抛出错误

Ras*_*had 5 php directory require include

我试图创建一个bootstrap文件,但每当我尝试在另一个文件中包含或要求它时,这样的错误会一直显示:

警告: require_once(../ folder/file.php)[function.require-once]:无法打开流:没有这样的文件或目录...

致命错误: require_once()[function.require]:在...中打开所需的'../folder/file.php'(include_path =':')失败

绘制整个场景:我有一个bootstrap文件,load.php.在其中,我连接到../config/config.php的配置文件.在加载文件上方,我在classes/database.php中有一个数据库类文件.在数据库文件中我写了这个if语句:

           if ( file_exists('../load.php') ) {
               echo 'load.php: It exists';
               require_once('../load.php');
           } else {
                  echo 'load.php: It does not exist';
                  }
Run Code Online (Sandbox Code Playgroud)

在加载文件中,我写了一个类似的if语句,但检查配置文件是否存在.令人惊讶的是,当我加载database.php文件时,我得到:

load.php: It exists
config.php: file doesn't exist
Run Code Online (Sandbox Code Playgroud)

但是当我加载load.php文件时,我得到:

config.php: It exists
Run Code Online (Sandbox Code Playgroud)

这是我的文件所在的位置:

根目录:/Library/WebServer/Documents/project

config.php文件 /Library/WebServer/Documents/project/config/config.php

load.php文件: /Library/WebServer/Documents/project/includes/load.php

database.php文件:/Library/WebServer/Files/project/includes/classes/database.php

我需要帮助解决这个bug.谢谢,

Ser*_*kyi 8

dirname(__FILE__) . '../relative/path/from/file/in/which/opened/to/config.php'.从PHP 5.3开始,也是__DIR__不变的