PHP 需要上面的文件夹

PHP require folder above

我的文件结构如下所示(不重要的文件被忽略):

Testserver
    -file.php
    PHP
        -functions.php
    Administration
        -index.php

现在,当我尝试调用 require_once('../PHP/functions.php');在 "index.php" 里面它不起作用,我不明白为什么。任何人都知道问题可能是什么?
这很好用:

require_once('../file.php');
  • 您是否收到 PHP 错误,如果是什么意思?
  • 检查 lowercase/uppercase 个问题

以下应该可以正常工作:

require_once('../PHP/functions.php'); 

您的文件夹结构如下:

Testserver
    -file.php
    PHP
        -functions.php
    Administration
        -index.php

然后,您在 index.php 中,试图访问目录 PHP 中的文件 functions.php。然后你需要从 index.php 文件的当前目录(即 Administration 目录)向上一个目录[意思是你从 AdministrationTestserver 文件夹] 文件夹],然后向下钻取到 PHP 目录。在代码中这意味着:

    <?php 
        require_once __DIR__ . "/../PHP/functions.php";

希望这对你有用。

干杯,祝你好运....

检查您对该文件夹的权限并尝试:

require_once('../PHP/functions.php')

首先感谢大家的回答,我现在找到了错误:
在 functions.php 中,我需要另一个文件,当我从 index.php
调用它时,该文件的路径不正确 所以我不得不更改 functions.php 内的路径而不是 index.php.
内的路径 仍然感谢大家的其他建议:)