include_once(../../config.php): 无法打开流:没有那个文件或目录

include_once(../../config.php): failed to open stream: No such file or directory

我的文件路径类似于 >>

/config.php
/fold_1/fold_2/functions.php
/fold_1/myfile.php

functions.php 包含 >>

include_once("../../config.php");
function addition($x,$y){return($x+$y);}
function substraction($x,$y){return($x-$y);}

myfile.php包含>>

include_once("fold_2/functions.php");
call addition(2,3);

但它会发出类似 >>

的警告
include_once(../../config.php): failed to open stream: No such file or 
directory 

我知道原因就像我在 myfile.php 中包含 function.php 它将把 function.php 的所有代码替换为 myfile.php 然后 运行 function.php 的代码,因此无法在 ../../config.php

找到 config.php 文件

但我想知道有没有什么解决方案(解决方案是改变php.ini中的一些变量值或类似的)来克服这个问题,这样它就可以运行 functions.php 的代码首先和之后它将映射到 myfile.php

尝试这样使用:

include_once $_SERVER['DOCUMENT_ROOT']. '/path/to/config.php';

有时 PHP 并且服务器更喜欢完整的绝对路径而不是 ../../ - 我通常使用 $_SERVER

修复