PHP Includes - relative Paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
faithfulman
Forum Newbie
Posts: 2
Joined: Mon Dec 08, 2003 12:54 am

PHP Includes - relative Paths

Post by faithfulman »

I've been using these include statements with php and they work great except for one slight problem. Okay, it's a big problem.


I want to make a banner that is on the top of all of my pages. So i have created a page banner.php in my include folder. Inside This page... it has a picture on it that is located in the root directory then in a images folder. So it looks like this:

<img src="images/background.jpg">


Now I want to reference this page not only on the index.php page that sits in the root directory, but also in the rest of my pages such as this.


http://www.domain.com/pages/test/file.php


But it isn't adding in the correct directory structure on it's own.

I need some way of having the include php statement automatically include the ../../../images/background.jpg on the files that need that. Just the same as any other directory that needs a reference to the banner page, where ever the current document is located.

Can anyone help me?

Thanks,

Kevin
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Why don't you use "/images/background.jpg" ?
I doubt you really need that paths relative.
faithfulman
Forum Newbie
Posts: 2
Joined: Mon Dec 08, 2003 12:54 am

What??

Post by faithfulman »

Because if I have a include statement that is in the root directory/include folder. and it makes reference to images/background.jpg


and I have another file that uses that include file such as a file located at pages/category1/test/page3.php

it willl look in pages/category1/test/images/background.jpg

and I want it to look back into the roo directory/images/background.jpg

Does anyone have a solution for me?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What weirdan suggested will do just that. Instead of realtive path, use root realtive paths i.e. paths that start with a leading forward slash.

Try it and you will see.

Mark
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

Post Reply