relative path (../path/to/file.php) does not work!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anjan011
Forum Newbie
Posts: 3
Joined: Thu Dec 18, 2008 10:24 am

relative path (../path/to/file.php) does not work!

Post by anjan011 »

Hi I am suddenly in this situation ..

i have a file structure like this --

incs
-----config.inc.php
-----db.inc.php
----------------
classes
-----cars.php
-----wheels.php
----------------

in cars.php i includes the config.inc.php by this ..

require_once('../incs/config.inc.php');

it gives me a fatal error -

Fatal error: require_once() [function.require]: Failed opening required
'../incs/config.inc.php' (include_path='.;C:\php5\pear') in
C:\wamp\www\NewFolder\classes\cars.php on line 5

but if i use this -

require_once('./incs/config.inc.php');

the script works perfectly ..

other scripts are running well with the ../incs/files.php but this script isn't

any help?

regards,
Anjan
corkman
Forum Newbie
Posts: 14
Joined: Thu Apr 09, 2009 3:40 am

Re: relative path (../path/to/file.php) does not work!

Post by corkman »

your include_path contains ".", so require should seek in the current directory.

So, if this works:
require_once('./incs/config.inc.php');
then the directory incs must be the the subdirectory of classes, where you run the script cars.php.

Are you sure, that the tree you drawn is correct?
Post Reply