Require_once PHP 错误

发布于 2024-11-19 10:27:04 字数 975 浏览 1 评论 0原文

我已经用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枕头说它不想醒 2024-11-26 10:27:04

也许您位于错误的工作目录中。无论如何,依赖它(除非你明确想要访问它)是一个坏主意。 使用

require __DIR__ . '/../fruit.php';

在 5.3 之前

require dirname(__FILE__) . '/../fruit.php';

或提醒,以 ... 开头的路径不会针对包含路径进行解析,而仅针对当前工作目录。

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

require __DIR__ . '/../fruit.php';

or with pre-5.3

require dirname(__FILE__) . '/../fruit.php';

Remind, that paths starting with .., or . are not resolved against the include-path, but only against the current work directory.

郁金香雨 2024-11-26 10:27:04

请记住,在第二种情况下,您指定了一个路径,但在第一种情况下它使用您的包含路径。也许在第二种情况下,您可以修改包含路径,而不是显式指定 .. 。

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

柏拉图鍀咏恒 2024-11-26 10:27:04

我知道这个问题很旧,但仍然相关。

根据我的经验, "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.

少钕鈤記 2024-11-26 10:27:04
require_once('fruit.php');

无论当前工作目录是什么,都会在与 widget.php 相同的目录中搜索fruit.php。

require_once('../fruit.php');

这将在当前目录上方的目录中搜索fruit.php,而不是在widget.php所在目录的上方目录中搜索。

require_once('fruit.php');

This searches for fruit.php in the same directory as widget.php is in, no matter what the current working directory is.

require_once('../fruit.php');

This searches for fruit.php in a directory above the current directory, not in the directory above the one widget.php is in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文