Page 1 of 1

include() referring to directory above

Posted: Thu Oct 25, 2007 5:35 am
by fredley
I'm in http://www.tommedley.com/customers/index.php and I want to include http://www.tommedley.com/lib.php. I know I can't use absolute paths, what is the correct syntax to refer to the parent (or root) directory?

Thanks

Fred

Posted: Thu Oct 25, 2007 6:27 am
by Rovas
Read here:
http://www.php.net/manual/en/function.include.php
Look at the Contributed Note by slush puppie in the same page.

Two things

Posted: Thu Oct 25, 2007 3:12 pm
by churt
First, you can use include "../file.php"; to get to a file in the parent directory.

However, this can cause issues if you ever include a file that has an include. In that case you can use:

Code: Select all

include $_SERVER['DOCUMENT_ROOT'].'path to file';
This starts you from the web document root and you can just put the full path. It's still a relative reference but no issues when including a file that includes another file.