Jump to content

Including files for a beginner!


dannyluked

Recommended Posts

Hi,

I am trying to include my header, footer, left and right in all my pages. These are all php documents and when I navigate to there URL (mysite.com/inc/left.php) they look fine. However, when they are included in mysite.com/index.php using the code:

<?php include "inc/left.php" ?>

they dont show any of the images. The images for the includes are in mysite.com/inc/img. I also must add that they are linked to the include files as img/header.png, not mysite.com/inc/img/header.png. Does this matter?

 

So, my overall questions are;

1. Why are my images not being displayed in index.php but are in mysite.com/inc/left.php?

2. Does having images in my css as img/header.png and not mysite.com/inc/img/header.png matter?

3. How do I link to the includes from the higher directories like mysite.com/example/index.php?

 

Thank you very much in advance!

Link to comment
https://forums.phpfreaks.com/topic/166865-including-files-for-a-beginner/
Share on other sites

So, my overall questions are;

1. Why are my images not being displayed in index.php but are in mysite.com/inc/left.php?

 

The images likely do not display because the way you are referencing the images.  Think of it this way, if the image is is actually in mysite.com/inc/img/myimage.jpg and you are calling the include from mysite.com then when the include is parsed it looks for images in mysite.com/img/myimage.jpg which doesn't exist.

 

2. Does having images in my css as img/header.png and not mysite.com/inc/img/header.png matter?

 

Yes, you should use full paths to your images if you intend on referencing them from other directories.

 

3. How do I link to the includes from the higher directories like mysite.com/example/index.php?

 

You can either use the full path or relative path, ie ../inc would bring you down a level and into the inc folder.

Thank you very much!!

 

This works. I have resolved with the method of using inc/img/image.gif instead of the full URL as the site host is only tempory and it saves me a lot of work!

 

Sadly I still cant link to includes from other directories. I think I worded it wrong in my other post. I want to include mysite.com/members/index.php into mysite.com/inc/left.php. what is the code for this. Also when I do this the images dont show again, but they do show in mysite.com/index.php!

 

PS. it wont let me use full URL's to include files!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.