PHP找到require_once真实路径 [英] PHP find require_once real path
问题描述
我需要require_once
此文件main.class.php
和functions.php
以及config.php
到admin/test.php
.如何找到所需的PHP路径真实!
i need to require_once
this files main.class.php
and functions.php
and config.php
to admin/test.php
. how to php find require real path?!
注意:class folder
中的main.class.php
,includes folder
中的functions.php
和root
目录中的config.php
和admin folder
中的test.php
.
NOTE: main.class.php
in class folder
, functions.php
in includes folder
and config.php
in root
directory and test.php
in admin folder
.
文件目录:
root
/admin/
->test.php
/class/
->main.class.php
/includes/
->functions.php
/templates
config.php
phpinfo.php
推荐答案
我将您的root
文件夹添加到包含路径并从那里开始工作.
I would add your root
folder to the include path and work from there.
来自admin/test.php
set_include_path(implode(PATH_SEPARATOR, array(
realpath(__DIR__ . '/..'),
get_include_path()
)));
require_once 'class/main.class.php';
require_once 'includes/functions.php';
require_once 'config.php';
更新
如果我正确地遵循了您的问题,假设您想在config.php
文件中定义此问题,则可以执行以下操作
Update
If I'm following your question correctly, assuming you wanted to define this in the config.php
file, you would do something like this
set_include_path(implode(PATH_SEPARATOR, array(
__DIR__,
get_include_path()
)));
require_once 'class/main.class.php';
require_once 'includes/functions.php';
admin/test.php
require_once __DIR__ . '/../config.php';
这篇关于PHP找到require_once真实路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!