php require_once :无法打开流:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5116421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
require_once :failed to open stream: no such file or directory
提问by luca
I have this testing code in "PAGE A":
我在“PAGE A”中有这个测试代码:
<?php
require_once('../mysite/php/classes/eventManager.php');
$x=new EventManager();
$y=$x->loadNumbers();
?>
"eventManager.php"has inside a require_once:
“eventManager.php”里面有一个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:
如果我在浏览器中测试 PAGE A,我会收到:
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
警告:require_once(../includes/dbconn.inc) [function.require-once]:无法打开流:在线 C:\wamp\www\mysite\php\classes\eventManager.php 中没有这样的文件或目录3
致命错误:require_once() [function.require]:在 C:\wamp\www\mysite\php 中打开所需的 '../includes/dbconn.inc' (include_path='.;C:\php5\pear') 失败\classes\eventManager.php 第 3 行
where is the error?
错误在哪里?
Thanks Luca
谢谢卢卡
采纳答案by Michiel Pater
You will need to link to the file relative to the file that includes eventManager.php
(Page A)
Change your code fromrequire_once('../includes/dbconn.inc');
您需要链接相对于包含文件的文件eventManager.php
(页A)
从改变你的代码require_once('../includes/dbconn.inc');
Torequire_once('../mysite/php/includes/dbconn.inc');
到require_once('../mysite/php/includes/dbconn.inc');
回答by Aron Rotteveel
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 pathto the file, using realpath()
, and use dirname(__FILE__)
to get your current directory:
尝试使用文件的完整路径,使用realpath()
和dirname(__FILE__)
获取当前目录:
require_once(realpath(dirname(__FILE__) . '/../includes/dbconn.inc'));
回答by Csharls
this will work as well
这也能工作
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/mysite/php/includes/dbconn.inc');
回答by Hao Zonggang
set_include_path(get_include_path() . $_SERVER["DOCUMENT_ROOT"] . "/mysite/php/includes/");
set_include_path(get_include_path() . $_SERVER["DOCUMENT_ROOT"] . "/mysite/php/includes/");
Also this can help.See set_include_path()
这也可以帮助。见 set_include_path()
回答by Benubird
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.
它说该文件C:\wamp\www\mysite\php\includes\dbconn.inc
不存在,所以错误是,您丢失了该文件。