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?
LVL 1
derridaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
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.
0
derridaAuthor Commented:
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.
0
Chris StanyonWebDevCommented:
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.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

derridaAuthor Commented:
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.
0
Chris StanyonWebDevCommented:
Ahh. Sorry - my mistake. You need to include the document root in the include path:

require_once($_SERVER['DOCUMENT_ROOT'] . '/configs/configs.php');
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
derridaAuthor Commented:
saved my life thanks :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.