My basic file structure something like:
domain.com/
home.php
images/
global/
nav/
nav-img.jpg
includes/
menu.php
fruit/
apples/
red/
gala/
gala.php
I want to create a global path establishing my web root that I can reference on the fly in each page wherever it resides. I'm trying to figure out how to use [for example] define(ROOT), and how to call it from an individual page.
Knowing that all pages use [menu.php], my obstacle is, for example:
From the gala.php page - when I click on [home], it looks for:
/fruit/apples/red/gala/home.php
But that doesn't exist.
Also, I'm trying to avoid these [2] things IF POSSIBLE:
Using html file references in gala.php like this: ../../../../includes/menu.php [to find the correct global include]
And avoid using link references in menu.php like this: /images/global/nav/nav-img.jpg
**
Update
**
- SOLVED
Like others have posted, I ended up using:
define('ROOT',$_SERVER['DOCUMENT_ROOT']);
define('INCLUDES',ROOT.'/path/to/includes/folder/');
which worked well when I call it from the html with:
include(INCLUDES.'menu.php'); // or any file
This was great because I can find my includes no matter where they're called from... and this was easy once I figured out how to use it.
**
Remaining Problem
**
[for #2 above] The only remaining problem is that all my html links in the includes are broken where the include is called from a level other than from ROOT.
I found a workaround is to just use absolute paths like:
href="/images/global/nav/nav-img.jpg"
Is there a way I can create a DOCUMENT_ROOT type of file reference for image locations so my includes will always find them?