require_once :failed to open stream: no such file or directory

本秂侑毒 提交于 2019-11-26 20:38:13

问题


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


回答1:


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');




回答2:


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'));



回答3:


this will work as well

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



回答4:


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.




回答5:


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

Also this can help.See set_include_path()



来源:https://stackoverflow.com/questions/5116421/require-once-failed-to-open-stream-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!