2
votes

Hello i'm running WAMP (32 Bit) server

i exec C:\wamp\www\1\index.php using browser with this address http://localhost:8080/1/

index.php has the follow code

require_once 'libraries/database/database.php';

database.php has the follow code

require_once '../misc/traits/singleton.php';

singleton.php is located in this location

C:\wamp\www\1\libraries\misc\traits\singleton.php

database.php is located in this location

C:\wamp\www\1\libraries\database\database.php

and there is error(s):

( ! ) Warning: require_once(../misc/traits/singleton.php): failed to open stream: No such file or directory in C:\wamp\www\1\libraries\database\database.php on line 3

( ! ) Fatal error: require_once(): Failed opening required '../misc/traits/singleton.php' (include_path='.;C:\php\pear') in C:\wamp\www\1\libraries\database\database.php on line 3

Thanks

1

1 Answers

2
votes

Paths stem from the php file that was originally executed, unless you change the path using chdir.

So use 'libraries/misc/traits/singleton.php'

If you want to do relative includes, use __DIR__, which is the directory of the CURRENT file.

e.g.

__DIR__ . '/../misc/traits/singleton.php'