require_once:无法打开流:没有这样的文件或目录

发布于 2024-10-19 08:00:38 字数 865 浏览 2 评论 0原文

我在“PAGE A”中有这个测试代码:

<?php
require_once('../mysite/php/classes/eventManager.php');
$x=new EventManager();
$y=$x->loadNumbers();
?>

“eventManager.php”内部有一个require_once:

<?php
require_once('../includes/dbconn.inc');
class EventManager {...}
?>

我的文件夹结构是这样的:

mysite/php/classes folder and includes folder

如果我在浏览器中测试PAGE A我收到:

警告:require_once(../includes/dbconn.inc)[function.require-once]:无法打开流:没有这样的文件或 在线目录 C:\wamp\www\mysite\php\classes\eventManager.php 3

<小时> 致命错误:require_once() [function.require]: 无法打开所需的 '../includes/dbconn.inc' (include_path='.;C:\php5\pear') C:\wamp\www\mysite\php\classes\eventManager.php 第 3 行

错误在哪里?

谢谢 卢卡

I have this testing code in "PAGE A":

<?php
require_once('../mysite/php/classes/eventManager.php');
$x=new EventManager();
$y=$x->loadNumbers();
?>

"eventManager.php" has inside a require_once:

<?php
require_once('../includes/dbconn.inc');
class EventManager {...}
?>

My folders structure is this:

mysite/php/classes folder and includes folder

If i test PAGE A in a browser i receive:

Warning: require_once(../includes/dbconn.inc) [function.require-once]: failed to open stream: No such file or
directory in C:\wamp\www\mysite\php\classes\eventManager.php on line
3


Fatal error: require_once() [function.require]: Failed opening required '../includes/dbconn.inc' (include_path='.;C:\php5\pear') in
C:\wamp\www\mysite\php\classes\eventManager.php on line 3

where is the error?

Thanks
Luca

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

时光无声 2024-10-26 08:00:39

它说文件 C:\wamp\www\mysite\php\includes\dbconn.inc 不存在,所以错误是,您丢失了该文件。

It says that the file C:\wamp\www\mysite\php\includes\dbconn.inc doesn't exist, so the error is, you're missing the file.

风吹雨成花 2024-10-26 08:00:38

该错误几乎解释了问题所在:您试图包含一个不存在的文件。

尝试使用该文件的完整路径,使用 realpath(),并使用 dirname(__FILE__) 获取当前的目录:

require_once(realpath(dirname(__FILE__) . '/../includes/dbconn.inc'));

The error pretty much explains what the problem is: you are trying to include a file that is not there.

Try to use the full path to the file, using realpath(), and use dirname(__FILE__) to get your current directory:

require_once(realpath(dirname(__FILE__) . '/../includes/dbconn.inc'));
帅哥哥的热头脑 2024-10-26 08:00:38

您需要链接到与包含 eventManager.php 的文件相关的文件(页面 A)

更改您的代码
require_once('../includes/dbconn.inc');


require_once('../mysite/php/includes/dbconn.inc');

You will need to link to the file relative to the file that includes eventManager.php (Page A)

Change your code from
require_once('../includes/dbconn.inc');

To
require_once('../mysite/php/includes/dbconn.inc');

方圜几里 2024-10-26 08:00:38

这也会起作用

 require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/mysite/php/includes/dbconn.inc');

this will work as well

 require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/mysite/php/includes/dbconn.inc');
沫离伤花 2024-10-26 08:00:38

set_include_path(get_include_path() . $_SERVER["DOCUMENT_ROOT"] . "/mysite/php/includes/");

这也有帮助。请参阅 set_include_path()

set_include_path(get_include_path() . $_SERVER["DOCUMENT_ROOT"] . "/mysite/php/includes/");

Also this can help.See set_include_path()

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