require_once :failed to open stream: no such file or directory
Asked Answered
K

5

24

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

Keeper answered 25/2, 2011 at 11:1 Comment(3)
"Where is the error?", Lol? Have you solved the problem yet?Branscum
yes michiel..but i think it would be better an absolute path!Keeper
Possible duplicate of Failed to open stream : No such file or directoryCoact
B
20

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

Branscum answered 25/2, 2011 at 11:3 Comment(0)
R
23

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'));
Racialism answered 25/2, 2011 at 11:5 Comment(1)
Just a note for Windows users: I had to change the solution above to require_once(realpath(dirname(FILE) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'util.php')); This will also work in Linux as well.Centaurus
B
20

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

Branscum answered 25/2, 2011 at 11:3 Comment(0)
E
7

this will work as well

 require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/mysite/php/includes/dbconn.inc');
Edinburgh answered 8/9, 2014 at 6:37 Comment(0)
A
1

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

Also this can help.See set_include_path()

Acatalectic answered 21/3, 2016 at 2:15 Comment(0)
R
0

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.

Residual answered 25/2, 2011 at 11:3 Comment(3)
it exists cause in dreamweaver is already linked to eventManager!!Keeper
Have you actually seen the file? Can you find it? If you open your text editor, select 'open file', and type in C:\wamp\www\mysite\php\includes\dbconn.inc, what does it say? file not found? Bingo.Residual
@benubird : i have same problem, and i check file still exist in path. what the problem that make that? i confusingHearten

© 2022 - 2024 — McMap. All rights reserved.