包含来自父目录或其他目录的文件 [英] Include files from parent or other directory

查看:90
本文介绍了包含来自父目录或其他目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm needing to include a file from the parent directory, and other sub-directories, into a sub-directory. I've done it before by simply using include('/rootdirectory/file.php'); but now it won't seem to work.

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

Just wondering how I can do this, thanks.

这是我的确切行:

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

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

It's giving me this error(the page still runs):

警告::include(/forums/groups.php)[function.include]:无法执行 开放式流:中没有这样的文件或目录

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

警告: include()[function.include]:打开失败 '/forums/groups.php'包含在内 (include_path ='.; C:\ xampp \ php \ PEAR')在 第3行上的C:\ xampp \ htdocs \ forums \ blog \ posts.php

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

推荐答案

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

include() and its relatives take filesystem paths, not web paths relative to the document root. To get the parent directory, use ../

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

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

If you begin with a /, an absolute system file path will be used:

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

这篇关于包含来自父目录或其他目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆