引用更高目录中的文件


Reference file in higher directory?

我的文件结构是这样的:

filethatineed.html
folder
    index.php

在索引.php中,我想引用 HTML 文件。

如果它在同一目录中,我会拥有以下内容:

<?php include('filethatineed.html');?>

当文件位于更高目录中时,我如何更改它以包含该文件?

<?php include('../filethatineed.html');?>

..的意思是"上面的一个目录"。

使用 include('../filethatineed.html') .

您可以使用相对路径模式喜欢对于当前文件夹上方的文件,则

<?php include('../filethatineed.html');?>

有以下方法可以包含文件

1. include($_SERVER['DOCUMENT_ROOT']."/filethatineed.html");
2. include(__DIR__."../filethatineed.html");
3. include('../filethatineed.html');