External PHP and images?


I am using PHP for setting up a header which would be same across the whole website. I’m using the ‘<?php include("common/header.php") ?>’ code to include the header file.

However, the image tag in the header.php file, the image doesn’t show on the main index.php file, but is displayed when I test the header.php file.

The index file can be viewed at: http://www.sanjayshahseminar.com/temp/
Header.php: http://www.sanjayshahseminar.com/temp/common/header.php

Looking for some help!

Hi there,

Try changing the src of your image to “/temp/images/logo.jpg”

The image is exactly placed there itself. That’s why it appears in the header.php file, right?

Well basically the “…/” at the beginning of your image src says to go back to the previous directory, so when that path is called from ./temp/common/ it goes back to ./temp/ and then looks for the images directory (which is correct). However, when you use that path in ./temp/ it goes back to the root of your site ./ - prepending your url with “/” tells it to always go to the root directory of the site, hence my suggestions of “/temp/images/”

It’s placed in the /temp/images/ folder since the beginning… That’s what I’m saying…

And that’s why it displays in the header.php file. My concern is why doesn’t it display in the main file : :frowning:

Yes, I know, my last post already answered that question. It’s the use of “…/” in the image src. Just change it to “/temp/images/logo.jpg” instead of “…/images/logo.jpg” and it will work.

You mean to say that the address should be with respect to the “index.php” file and not the “header.php” file?

Tried it. And it worked :o.

Still can’t figure out why though… Because, now, I would have to make another header file I guess. For the other pages which I will put in separate folders. Say, the “video.php” goes in the Videos folder. So, there again, it would have to be “…/images/logo.jpg” right?

Basically, in regards to locations in HTML (img src, form action,a href etc) you will need to make the link in respect to the file that is ultimately calling the file with that information. So if you have your http://www.sanjayshahseminar.com/temp/index.php with an include for http://www.sanjayshahseminar.com/temp/videos/video.php - any references to file locations in HTML tags will need to be as if you are typing it in the index.php, as it is only in this point that the HTML is printed and parsed.

Whatever page you are on when you see data, the paths should be as of that path (ignore the location of the php file - if file2.php being included in index.php and they are 3 directories away, the img paths would still be the same, whether it was in index.php or file2.php because even though the php files are in different locations, the location at which the HTML is outputted is the same).

Hopefully this clarifies? If it doesn’t don’t worry, you will understand eventually, it just takes some time to get used to.

I get that :).

Thanks a lottt :D!

Take care ;).

Sponsor our Newsletter | Privacy Policy | Terms of Service