I have a sidebar.php which contains:

<a href="page.html"><src="images/MyImage.gif"></a>

If I do:

<?php include 'sidebar.php';?>

from a file that is in '/', everything works properly (because it looks in /images for the gif).

However, if I do:

<?php include '../sidebar.php';?>

from a file in, say, '/Example', the image is not displayed.

After some searching I found that I could supposedly add a '/' to the beginning of the path:

<a href="page.html"><src="/images/MyImage.gif"></a>

but when I do this the image does not display in EITHER case.

Any thoughts?



Edited by daviddoria: n/a

7 Years
Discussion Span
Last Post by Arkinder


The / in front of the path and filename is based on your DocumentRoot for the site in question. I would check the httpd.conf for the reference and see where it points.

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common


This is the site:


I only have ftp access, and it seems like '/' is where my index.php is. I don't see a httpd.conf, so I'm assuming its at a location "above my pay grade"? Since it seems like the problem is that '/' is not what we expect, could I make a variable:

ROOT = http://ewh.ieee.org/r1/schenectady/

and then include the images like:



The problem is that since this page (sidebar.php) gets included from different levels of the directory structure, hard coding ../images/image.jpg versus simply images/image.jpg is not an option, because the correct relative path is different based on where sidebar.php was included from.


Oh I see, it actually needs to 'echo' the text so that it creates the page with that line. Can I define $ROOT more "globally" so I can use it through many files?


I don't know enough about PHP's variable scope to tell you for sure, but I don't think so.

Regards, Arkinder

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.