Page 1 of 1

Problem defining paths inside included PHP file

Posted: Mon Feb 04, 2008 3:12 am
by grahamporter
I'm setting up my first website using DW8/PHP5 and apache for local testing.

I've created a PHP file with code for a navigation bar which has html code pointing at various images. When I create pages in the site root directory this works fine, as the html image links are set to "images/some.gif".

However, I have set up a tree of directories for my content and when I use the include in pages below the root, the image file are no longer found as the image links start looking in the current directory.

I assume I need to add some code to the include file so the img src tag is always going to look in the correct directory no matter where the page is created. I've been trying for ages to figure this out, but so far without success. I am on the wrong track here? Here's an example:

Navbar.php
<div id="logoheader"><img src="Images/some.gif"/></div>

SiteRoot contains:
page_one
Navbar.php

SiteRoot\Images contains:
some.gif

SiteRoot\Content contains:
page_two

page_one works fine as it is created in the site root. But page_two doesn't.

Any help would be appreciated by a frustrated newbie! :-)

Graham

Re: Problem defining paths inside included PHP file

Posted: Mon Feb 04, 2008 3:18 am
by Christopher
Since page_two.php is in the Content directory, the relative path to the images would be "../images/some.gif"". The absolute path to the images would be something like "http://localhost/SiteRoot/images/some.gif"".

Re: Problem defining paths inside included PHP file

Posted: Mon Feb 04, 2008 3:36 am
by grahamporter
Thanks for the reply.

Can't use the "../" syntax in the include file as it's included into pages in two different directories, but the absolute path seems to have done the trick.

One more silly question. When I publish the site I assume I'll have to change the references to localhost to the actual address eg. http://www.somesite.com, or is the localhost always defined as the correct address?

Thanks again for the prompt reply.

Graham

Re: Problem defining paths inside included PHP file

Posted: Mon Feb 04, 2008 4:14 am
by Christopher
You will need to change it to the correct URL.

Re: Problem defining paths inside included PHP file

Posted: Mon Feb 04, 2008 6:02 am
by grahamporter
Thought so.

Thanks for the assist.