Jump to content

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">

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.