小编典典

包含来自父目录或其他目录的文件

php

我需要将父目录和其他子目录中的文件包含到子目录中。我之前只使用include(’/ rootdirectory / file.php’);
但现在看来似乎行不通。

只是想知道我该怎么做,谢谢。

这是我的确切行:

include('/forums/groups.php');

它给我这个错误(页面仍在运行):

警告: include(/forums/groups.php)[function.include]:无法打开流:C:\ xampp \
htdocs \ forums \ blog \ posts.php中没有这样的文件或目录

警告: include()[function.include]:无法在C:\ xampp \ htdocs \ forums \
blog中打开’/forums/groups.php’以便包含(include_path =’.; C:\ xampp \ php \ PEAR’) \
posts.php在第3行


阅读 313

收藏
2020-05-29

共1个答案

小编典典

include()及其相对对象采用文件系统路径,而不是相对于文档根目录的Web路径。要获取父目录,请使用../

include('../somefilein_parent.php');
include('../../somefile_2levels_up.php');

如果您以开头,/则将使用绝对系统文件路径:

// Full absolute path...
include('/home/username/sites/project/include/config.php');
2020-05-29