-1

when I add an include to my header, i get broken photos.

example:

enter image description here

my code:

<?php virtual('includes/nav.php'); ?>

is there a problem in my code?

html:

<ul>
  <li><a href="#">HOME</a> </li>
  <li><a href="#">PLAY</a> </li>
  <li><a href="#">ABOUT</a></li>
  <li><a href="http://fb.com/officialninjaa"><img src="../images/facebook.png" width="60" height="17" /></a></li>
  <li><a href="http://twitter.com/martinshamasha"><img src="../images/twitter.png" width="64" height="17" /></a></li>
</ul>
  • Try `src="/images/twitter.png"` etc. – Funk Forty Niner Jul 21 '14 at 19:07
  • That's an simple clue, that your source is not correct. Try the absolute path. – Tyralcori Jul 21 '14 at 19:08
  • Does `/images/twitter.png` exist on your server? – Fallenreaper Jul 21 '14 at 19:08
  • 1
    Do you really need to include your nav.php file with the `virtual()` function? What happens if you try `include()` instead? –  Jul 21 '14 at 19:14
  • The browser only downloads what you've told it to download. Right click the images and inspect the URLs you've provided. Understand then the issue, try to understand the cause and learn about URLs, you will need that more than once. – hakre Jul 21 '14 at 19:14

2 Answers2

2

virtual() performs an Apache sub-request, which causes URLs to be relative to the directory of the resource being accessed by that sub-request. So here:

<img src="../images/facebook.png" width="60" height="17" />

Since virtual() is executing 'includes/nav.php', the image's src attribute is pointing to 'images/facebook.png' relative to the original URL (not '../images/facebook.png').

To avoid confusion like this, try using absolute URLs instead of relative URLs:

<img src="/docroot/path/to/images/facebook.png" width="60" height="17" />

For your reference here is the official documentation on this function: virtual()

Adelmar
  • 2,073
  • 2
  • 20
  • 20
0

Try changing the source of the image to the root

/images/facebook.png
user2075215
  • 379
  • 5
  • 21
  • ok the images worked, the issue was the path but when i upload it on my localhost server it wont display the photos. – Martin Shaba Jul 21 '14 at 19:16