gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:58:45 24 4
gpt4 key购买 nike

我需要将父目录和其他子目录中的文件包含到子目录中。我以前通过简单地使用 include('/rootdirectory/file.php'); 来完成它。但现在它似乎不起作用。

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

这是我的确切路线:

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

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

Warning: include(/forums/groups.php) [function.include]: failed toopen stream: No such file or directory inC:\xampp\htdocs\forums\blog\posts.php on line

Warning: include() [function.include]: Failed opening'/forums/groups.php' for inclusion(include_path='.;C:\xampp\php\PEAR') inC:\xampp\htdocs\forums\blog\posts.php on line 3

最佳答案

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

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

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

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

关于php - 包含来自父目录或其他目录的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8826567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com