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?

Thanks,

David

Recommended Answers

All 8 Replies

Hello,

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
#</VirtualHost>

Have a look a this to better understand how file paths work.

Regards, Arkinder

@rch1231

This is the site:

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

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:

ROOT/images/image.jpg

?

@Arkinder
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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.