包含来自不同目录的文件

seo*_*ppc 1 php

以下是我的文件目录结构...

Config
   config.php (is calling some files too like includes/class.DB.php)
Run Code Online (Sandbox Code Playgroud)

现在我已经创建了另一个文件夹Admin并创建了新的config.php(并通过调用root配置文件require_once '../config/config.php';)正确加载配置文件,但在includes/class.DB.php上显示错误.

我希望,通过使用,您已经了解了我的问题,实现这一目标的方法是什么 DIR_NAME/ $SERVER['DOCUMENT_ROOT']

请帮忙.

gen*_*sis 9

使用

dirname(__FILE__); // or, if you have +5.3, use __DIR__ instead
Run Code Online (Sandbox Code Playgroud)

所以,如果你有这个结构

includes
    -class.php
admin
    -admin.php
config
   -config.php
Run Code Online (Sandbox Code Playgroud)

所以你可以使用

//admin.php
include(dirname(__FILE__)."/../config/config.php");

//config.php
include(dirname(__FILE__)."/../includes/class.php");
Run Code Online (Sandbox Code Playgroud)

它总是瞄准同一个目录!