Avatar of krypto2000
krypto2000 asked on

PHP require and relative path problem

Hi  !

I developped a library in PHP5 and  putted it into a directory of my website ("classes").
I created then three subfolders : "business", "data", "interface"
so my layer are well separeted. But of course, some files from the "business" directory must reference some files from the "data" directory.

Everything works fine as long as I include thoses classes from php document which are located into my root directory.

Example :
index.php -> require_once 'classes/business/user.class.php' ==> OK

but then :
order/order_details.php -> require_once '../classes/business/user.php' ==> FAIL

But where the error occurs is not in the order_details.php file but in the user.class.php which can't find other required files that are not in the same directory as user.class.php (ex : classes/data/database.class.php which is referenced as ../data/databse.class.php)

Is there a way to make that works ? I don't want to put all my interface files in the root directory and i want to be able to use my classes from anywhere in my website !

Please help it is urgent !!!

(I hop it is clear :-/ Feel free to ask me more details)

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks for you help
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy