require_once:无法打开流:没有这样的文件或目录
我在“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它说文件
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.该错误几乎解释了问题所在:您试图包含一个不存在的文件。
尝试使用该文件的完整路径,使用
realpath()
,并使用dirname(__FILE__)
获取当前的目录: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 usedirname(__FILE__)
to get your current directory:您需要链接到与包含
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');
这也会起作用
this will work as well
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()