[thelist] weird include() problem in PHP

Ray Hill lists at prydain.com
Sat Mar 30 16:51:01 CST 2002

> "if file a includes file b, and file b wants to include
> file c, then include() does not provide any way to include
> c with a path relative to b,it can only specificy paths
> relative to a. This is a major obstacle for creating
> larger projects directly in PHP."

The way I've gotten around this in the past is to always create a
$root variable at the top of each page that represents the path back
to the root of the current project.  For instance, if the page you're
on is /folder_one/folder_two/pageone.phppp, it owuld be:

   $root = "../../";

Then, when you want to include something, start with $root and then
build the path from there.  So including a file in
/folder_one/another_folder/even_deeper/ would look like this, without
having to worry about where that is in relation to the current

   include($root . "/folder_one/another_folder/even_deeper/file.php");

This methos has worked pretty well for me so far.


More information about the thelist mailing list