Require_once PHP 错误
我已经用 PHP 编程好几年了,之前从未遇到过这个错误。
这是我的 widget.php 文件:
require_once('fruit.php');
echo "I am compiling just fine!!!";
和我的 fruit.php 文件:
$bVar = true;
当这两个文件看起来像这样 ^ 时,所有内容都会正确编译,并且我得到“我编译得很好!!!”成功消息。
现在,当我将 fruit.php 文件向上移动一级目录并更改 widget.php 文件以反映目录重组时:
require_once('../fruit.php');
echo "I am compiling just fine!!!";
现在突然间,我得到了PHP 警告 &致命错误:
Warning: require_once(../fruit.php) [function.require-once]: failed to open stream: No such file or directory in /webroot/app/widget.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../fruit.php' (include_path='.:/usr/local/php5/lib/php') in /webroot/app/widget.php on line 1
在我使用 PHP 的这些年里,我以前从未见过 require_once() 出现这样的失败。有什么想法吗?!?!
I've been programming in PHP for several years now and never encountered this error before.
Here's my widget.php file:
require_once('fruit.php');
echo "I am compiling just fine!!!";
And my fruit.php file:
$bVar = true;
When these two files look like this ^ then everything compiles with no errors and I get the "I am compiling just fine!!!" success message.
Now, the minute I move the fruit.php file one directory level up, and change my widget.php file to reflect the directory restructuring:
require_once('../fruit.php');
echo "I am compiling just fine!!!";
Now all the sudden, I get PHP warnings & fatal errors:
Warning: require_once(../fruit.php) [function.require-once]: failed to open stream: No such file or directory in /webroot/app/widget.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../fruit.php' (include_path='.:/usr/local/php5/lib/php') in /webroot/app/widget.php on line 1
In all my years working with PHP, I've never seen require_once() fail like this before. Any ideas?!?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许您位于错误的工作目录中。无论如何,依赖它(除非你明确想要访问它)是一个坏主意。 使用
在 5.3 之前
或提醒,以
..
或.
开头的路径不会针对包含路径进行解析,而仅针对当前工作目录。Maybe you are in the wrong work directory. Its a bad idea to rely on it (except you explictly want to access it) anyway. Use
or with pre-5.3
Remind, that paths starting with
..
, or.
are not resolved against the include-path, but only against the current work directory.请记住,在第二种情况下,您指定了一个路径,但在第一种情况下它使用您的包含路径。也许在第二种情况下,您可以修改包含路径,而不是显式指定 .. 。
http://php.net/manual/en/function.set-include -path.php
Remember that in the second case, you're specifying a path, but in the first case it uses your includes path. Perhaps rather than explicitly specifying .. in the second case, you case modify your include path.
http://php.net/manual/en/function.set-include-path.php
我知道这个问题很旧,但仍然相关。
根据我的经验, "open_basedir" 指令 是最有效的可能会导致这个问题。
I know the question is old, but it is still relevant.
In my experience, the "open_basedir" directive is most likely to cause this issue.
无论当前工作目录是什么,都会在与 widget.php 相同的目录中搜索fruit.php。
这将在当前目录上方的目录中搜索fruit.php,而不是在widget.php所在目录的上方目录中搜索。
This searches for fruit.php in the same directory as widget.php is in, no matter what the current working directory is.
This searches for fruit.php in a directory above the current directory, not in the directory above the one widget.php is in.