This is probably a very simple question (I hope), but my usually great
web searching abilities have not turned up the answer I am looking for.
I have a php page that includes a file for example index.php has an
include for menu.htm. Inside menu.htm are some images in the same
directory. All works great in that scenario.
Here's where the trouble begins. If I want to include menu.htm inside
a php file that is in another directory (say testdir/page.php) it is
unable to load the images because it is assuming the images are in the
same directory as page.php... it does not know the images are in the
directory above (the same directory that menu.php is in).
So when including a file that is contained within another directory,
the including page (testdir/page.php) uses the currenty directory as
the starting point when evaluating relative paths... because of this
it's looking for the images in the same directory that it's in..
instead of in the above directory like menu.htm indicates. Not sure if
that makes sense... here is an example of the pages / directories.
for example:
c:\php\index.php
c:\php\menu.htm
c:\php\menuimage.jpg
c:\php\testdir\page.php
==============================
code for index.php [WORKS]:
==============================
<? include ("menu.htm") ?>
==============================
==============================
code for page.php [Does not work. cannot load images]:
==============================
<? include ("../menu.htm") ?>
==============================
/\
|
|
\/
even though menu.htm is in the same directory as the .jpg file it is
looking for the .jpg in the directory it's being called from
(testdir)... the same directory that the including page (page.php) is
in.
Hope this makes sense. Is there a php function that can correc this
easily or am I using the include wrong? I have been able to correct
this by writing code that checks the URL and changes the reletive path
depending on which dir the including page is in... but that seems way
to complicated for this issue. I know there must be a simpler way.