Jump to content

php not displaying images


emvy03

Recommended Posts

Hi guys,

I'm building a website in php and am trying to 'include' a php page into the main index file. However, the problem I have is that while images display fine in the standalone php file, when I 'include' this in my index file the images wont display. Instead I get the broken link symbol.

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/240561-php-not-displaying-images/
Share on other sites

If you have a directory structure that looks like this:

 

  • home
    • images
      • navimg1.jpg
      • navimg2.jpg

      [*]includes

      • main_navigation.html

      [*]index.php

 

Keep in mind that the image path for main_navigation.html when it's included in index.php does not start in the includes folder. Instead it starts in the home folder since that's where index.php is located.

 

To avoid this type of issue, use root-relative links in the main_navigation.html file. So instead of:

 

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

 

You could use:

 

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

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.