XAMPP 不能要求父目录

XAMPP cannot require parent directory

我面临以下问题:

在我的 php 文件中,我尝试要求一个位于不同目录中的文件。

require (__DIR__."../../../../library/test.php");

当我启动需要文件的页面时,出现此错误:

require(): Failed opening required 'C:\xampp\htdocs\Webcontrol\app\modules\nastaveni\ajax\import../../../../library/test.php' (include_path='.;C:\xampp\php\PEAR;C:\xampp\htdocs')

似乎 php "thinks" 我正在输入我想要的文件的绝对地址,但我不知道如何 "tell" 我想要的输入一个相对地址。

谢谢

__DIR__ returns 没有尾部斜杠的路径。这在你得到的错误中是可见的。所以只需将您的要求更改为 require (__DIR__."/../../../../library/test.php");