抱歉问这个问题,因为之前可能已经回答过很多次了,但我的问题有点不同
我有像树一样
/var/www/path/to/my/app/
-- index.php
-- b.php
-- inc/
-- include.php
(我正在从index.php访问inc/include.php,
include "inc/include.php";
)
但在 include.php 中,我需要获取 APPLICATION root 的绝对路径,而不是 DOCUMENT_ROOT
所以结果,我需要能够使用这个命令
//inc/include.php
include(APP_ROOT."/b.php");
重复一遍,我不想这样称呼它
include("../b.php");
如果可能的话,是否有本机功能?
UPDATE:
我想通过 PHP 获取 PATH,因为任何开源都需要进行此路径检测
为什么?如果我想包含 ajax/1/somethiing.php 中的 inc/include.php,它会成功,但 inc/include.php 然后会尝试包含 ajax/b.php 而不是 b.php
对于佩卡:
我有这棵树
-- index.php
-- b.php
-- inc/
-- include.php
-- ajax/
-- 1/
-- ajax.php
现在看。从index.php,您将调用inc/include.php
include("inc/include.php"); //included file
现在,包含的文件搜索
include("../b.php");
它会起作用,但是!如果我从 ajax/1/ajax.php 调用包含 inc/include.php,如下所示
include("../../inc/include.php");
它会起作用,但包含的文件将尝试包含
../b.php
代替
../../b.php 作为路径相对于包含 inc/include.php 的文件
知道了 ?