0

The header for my website is the same across all of it so instead of rewrite the code and link the style sheets, i've decided to use the <?php include ;?> to put it at the top of every document.

My issue is that the logo that should come with the header isn't displaying.

File Structure

File Structure

enter image description here

As you can see, the header file is where it is and the logo named "Picture2.png" is in the image folder.

PHP

<?php include('./_/includes/header.php'); ?>

HTML (In header.php)

<nav id="navigation">
<ul id="navList">
    <li id="navLogo"><img src="/image/Picture2.png"/>Computing</li>
    <li><a class="navItem" href="gallery.php">Gallery</a></li>
    <li><a class="navItem" href="topics.php">Core Topics</a></li>
    <li><a class="navItem" href="courseview.php">Courses</a></li>
    <li><a class="navItem" href="index.php">Home </a></li>
</ul>
</nav>

Part of header that isnt' displaying correctly

enter image description here

NOTE** everything else in the header is correctly displayed, I'm using a local server, should that make a difference

KyleHodgetts
  • 317
  • 1
  • 4
  • 13

2 Answers2

3

You are using an absolute path for your image.

You should put and use a relative path :

<img src="_/includes/image/Picture2.png"/>

instead of

<img src="/image/Picture2.png"/>
Pierrickouw
  • 4,644
  • 1
  • 30
  • 29
  • 1
    With that being said, it should be noted that the issue is because his docroot is not what he thinks it is. – Ohgodwhy Apr 15 '14 at 03:10
  • That didn't change anything, i did initially try that – KyleHodgetts Apr 15 '14 at 03:11
  • You have to consider the location of the file where you are including your other file (probably index.php). Look the url you use to access your page, then you build the relative path starting from there. (I changed my answer) – Pierrickouw Apr 15 '14 at 03:17
  • I did that and even placed the picture in the same directory as header.php and still the same result – KyleHodgetts Apr 15 '14 at 03:27
  • If you just copied/pasted what I did, I had a typo (missing the "s" for "include" directory) – Pierrickouw Apr 15 '14 at 03:53
0

Yep, hes using an absolute path for image, but the project isn't in server root folder then you need's to inform the name of the folder in path...

Use <img src="/finalprojectneat/image/Picture2.png"> then you have your logo display on every page. But is not the most indicated because when you send to production server, you didn't have the "finalprojectneat" folder then you have to remove all paths using "projectneat".

One solution is to define a constant in your "index.php", not necessary in "index.php" but required in root folder of project

define ('_IMAGES_', realpath(dirname(__FILE__) . '/image'));

if you put this constant in another file inside root folder, use "require" to import these constants to your views...

and in your views, use

<?php echo _IMAGES_ . '/Picture2.png'; ?>
Thiago França
  • 1,817
  • 1
  • 15
  • 20