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
include() referring to directory above
Moderator: General Moderators
Read here:
http://www.php.net/manual/en/function.include.php
Look at the Contributed Note by slush puppie in the same page.
http://www.php.net/manual/en/function.include.php
Look at the Contributed Note by slush puppie in the same page.
Two things
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:
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.
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';