Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何列出require_once()';在PHP中搜索路径?_Php_Include_Require - Fatal编程技术网

如何列出require_once()';在PHP中搜索路径?

如何列出require_once()';在PHP中搜索路径?,php,include,require,Php,Include,Require,我们以前都见过这个错误: Warning: require_once(test/blah.inc) [function.require-once]: failed to open stream: No such file or directory in /home/narf/narf.inc on line 3 Fatal error: require_once() [function.require]: Failed opening required 'test/blah.inc' (inc

我们以前都见过这个错误:

Warning: require_once(test/blah.inc) [function.require-once]: failed to open stream: No such file or directory in /home/narf/narf.inc on line 3

Fatal error: require_once() [function.require]: Failed opening required 'test/blah.inc' (include_path='.:/usr/lib64/php:/usr/lib/php:/home/narf/inc:/home3/narf/php:/home3/narf/inc/dev:') in /home/narf/narf.inc on line 3
超级讨厌

以下是我想要的: 某种类型的PHP代码段,将列出正在搜索包含文件的路径。

从我所看到的,我已经正确地设置了路径(上面的include场景只是虚构的),并且我可以成功地从项目的其他部分包含该文件

然而,我就是不能让它工作。如果我有一个被搜索位置的列表,我可以很容易地找到我丢失的路径,并确定我的require/include不起作用的原因

想法?有人有没有可以分享的片段

提前感谢一百万!:)

编辑:不管它值多少钱,我想我已经找到了问题所在,但是如果你仍然有一些可以帮助你解决的东西,那对于将来的错误配置将是非常好的!:)


编辑2:感谢所有回答的人。获取include路径很好,但我要查找正在搜索的目录的实际绝对路径。我之所以如此挑剔,是因为在使用require()或include()以及相对路径时会感到困惑。此外,我怀疑还有其他一些问题,例如(可能)给定设置中是否遵循符号链接等。

引用手册的第页:

文件是根据文件类型包含的 给定的路径,如果未给定,则
包含指定的路径
如果文件 在
包含路径中找不到,
include()
将最终签入 调用脚本自己的目录和 之前的当前工作目录 失败的


并且是一个配置指令(引用):

指定目录列表,其中
require()
include()
fopen()
file()
readfile()
file\u get\u contents()
函数查找 档案

它可以在
php.ini
文件中配置,也可以在运行时使用函数进行配置


当然,要获取include路径,您必须。

您需要函数
get\u include\u path()
路径列在错误消息中:它是include\u路径中的值。终于找到了正确的道路。结果我需要:“require_once('../../../www/blog/wp load.php');”这毫无意义,但至少我的脚本现在正在运行。也许我以后会为每个人编写一个脚本,列出所有搜索到的绝对路径。另外,我本来应该提到我在include语句中使用相对路径(有时使用“../x/y/z”,有时仅使用“x/y/z”)(如上所示),因此PHP的include路径只是部分相关(仅在“x/y/z”包含的情况下)。来自include()的文档:“如果定义了路径-无论是绝对路径…还是相对于当前目录(以.or..开头)-将完全忽略include_路径。”选择此答案作为“正确”答案,因为它将帮助访问此页面的大多数人。从技术上讲,我正在寻找一些可以为我提供正在搜索的绝对路径列表的内容,但这似乎不存在。创建一个函数来执行此操作不会太复杂;也许我会重新访问它他的问题,并在稍后发布代码片段。感谢所有回答的人!:)