Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

path issue

Hi
i have a database class that require_once a config file like so:  require_once  'configs/configs.php';

all works until i require that class from a vertain folder, then the require inside the class doesn't work and i get:
<b>Warning</b>:  require_once(configs/configs.php): failed to open stream: No such file or directory

any idea?
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Without a leading slash, you'll get a relative path (relative to the folder your calling script is in).

Add a leading slash and you'll get an absolute path, always starting at the root. You probably need to add the leading slash:

    require_once(/configs/configs.php)

This will always load it from the /configs folder.
Avatar of derrida
derrida

ASKER

still get the same result.
i need that whereever i call the databse class the configs will work. now it work from some places and doesn't work on others.
If you want it to work from wherever you call it then you will need to use an absolute path, and not a relative one. a relative path is always 'relative' the the script you're calling from. An absolute path is the same, no matter where you call it from.
Avatar of derrida

ASKER

that's what i'm trying to do now and fail. how do i set an absolute path to the configs file in the database class? i have played with realpath but doesn't work.

i have a classes folder and the class is in there. i have a configs folder and the configs file is there. both the classes and the configs folders are in the root folder.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida

ASKER

saved my life thanks :)