Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 207
luca Avatar asked Feb 25 '11 11:02

luca


1 Answers

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')); 
like image 73
Aron Rotteveel Avatar answered Sep 28 '22 06:09

Aron Rotteveel