23

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

DamiToma
  • 921
  • 3
  • 9
  • 27
luca
  • 36,606
  • 27
  • 86
  • 125

5 Answers5

22

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'));
Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
  • 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. – carlosrafaelgn Jun 16 '20 at 12:01
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');

Michiel Pater
  • 22,377
  • 5
  • 43
  • 57
6

this will work as well

 require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/mysite/php/includes/dbconn.inc');
Csharls
  • 550
  • 8
  • 19
1

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

Also this can help.See set_include_path()

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.

Benubird
  • 18,551
  • 27
  • 90
  • 141
  • 1
    it exists cause in dreamweaver is already linked to eventManager!! – luca Feb 25 '11 at 11:14
  • 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. – Benubird Feb 25 '11 at 14:08
  • 2
    @benubird : i have same problem, and i check file still exist in path. what the problem that make that? i confusing – AsepRoro Oct 11 '13 at 03:14