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

7
  • Why the _/? Have you tried include('./includes/header.php') ? Commented Apr 15, 2014 at 3:09
  • That won't make a difference, everything but the image is displaying correctly Commented Apr 15, 2014 at 3:10
  • Scratch that above comment, I see what you're using now. Commented Apr 15, 2014 at 3:10
  • Your index.php and gallery.php etc. files are outside of those sub-folders I take it. Commented Apr 15, 2014 at 3:13
  • Those are in the "finalprojectneat" folder What i don't understand is why the rest of the header is showing but not the image? Commented Apr 15, 2014 at 3:14

2 Answers 2

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"/>
Sign up to request clarification or add additional context in comments.

5 Comments

With that being said, it should be noted that the issue is because his docroot is not what he thinks it is.
That didn't change anything, i did initially try that
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)
I did that and even placed the picture in the same directory as header.php and still the same result
If you just copied/pasted what I did, I had a typo (missing the "s" for "include" directory)
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'; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.