包含来自不同目录的文件 [英] include file from different directory
本文介绍了包含来自不同目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的文件目录结构...
following is my files directory structure...
Config
config.php (is calling some files too like includes/class.DB.php)
现在我已经创建了另一个文件夹 Admin ,并创建了新的 config.php (并通过require_once '../config/config.php';
调用根配置文件),其加载配置文件正确但显示错误 includes/class.DB.php .
Now i have created another folder Admin and created new config.php (and calling root config file by require_once '../config/config.php';
) its loading config file correctly but showing errors on includes/class.DB.php .
我希望,您已经对我的问题有所了解,通过使用DIR_NAME/ $SERVER['DOCUMENT_ROOT']
I hope, you have got my an idea of my problem, what is the way to achieve this, by USING DIR_NAME/ $SERVER['DOCUMENT_ROOT']
请帮助.
推荐答案
使用
dirname(__FILE__); // or, if you have +5.3, use __DIR__ instead
所以如果你有这个结构
includes
-class.php
admin
-admin.php
config
-config.php
因此您可以使用
//admin.php
include(dirname(__FILE__)."/../config/config.php");
//config.php
include(dirname(__FILE__)."/../includes/class.php");
它始终瞄准同一目录!
这篇关于包含来自不同目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文