Author Topic: [Solved] Including header from a different directory  (Read 776 times)

Offline mydas

  • Level 2
  • *
  • Posts: 4
  • Reputation: +0/-0
    • View Profile
[Solved] Including header from a different directory
« on: March 14, 2011, 05:48:49 AM »
Hi guyz,

I'm havin' problems with including a header file from another directory.

i.e. when i'm including 'header.php' (that uses images with path 'style/x.jpg'), all is fine in dandy, but when i go to 'admin/index.php' and include '../header.php', the images don't show.

What to do? ^^
« Last Edit: March 15, 2011, 05:19:27 AM by mydas »

Offline chrisjenkinson

  • Level 10
  • *
  • Posts: 61
  • Reputation: +0/-0
    • View Profile
    • Xiphos
Re: Including header from a different directory
« Reply #1 on: March 14, 2011, 06:04:59 AM »
Use absolute paths for your image files.

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: Including header from a different directory
« Reply #2 on: March 14, 2011, 06:09:55 AM »
An example of an absolute path would be '/images/my-awesome-title.png', the leading '/' in the path tells the browser to download the image from the document root, so say for example your domain was 'http://www.example.com' and you were in your admin direction, with the loading '/' it would download the image from 'http://www.example.com/images/my-awesome-title.png'.

But without the leading slash, like you currently have, the browser is appending the file path onto the currently active directory, so whats happening is the browser is looking for a file at 'http://www.example.com/admin/images/my-awesome-title.png', which is what is causing you issues.

Offline mydas

  • Level 2
  • *
  • Posts: 4
  • Reputation: +0/-0
    • View Profile
Re: Including header from a different directory
« Reply #3 on: March 14, 2011, 10:35:31 AM »
Ok, makes sense.

But currently I'm using Wamp, which means the site is hosted locally, and '/' refers to my current root of the drive, and that's not the same as the document root.

How do I find out the document root, and address it?

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: Including header from a different directory
« Reply #4 on: March 14, 2011, 10:40:11 AM »
Within wamp / isn't the same as c:/, when you do '/images/title.png' that should map to 'localhost/images/title.png', which depending on how you have wamp installed should be something like 'c:/wamp/www/images/title.png'.

Offline mydas

  • Level 2
  • *
  • Posts: 4
  • Reputation: +0/-0
    • View Profile
Re: Including header from a different directory
« Reply #5 on: March 14, 2011, 01:43:42 PM »
Within wamp / isn't the same as c:/, when you do '/images/title.png' that should map to 'localhost/images/title.png', which depending on how you have wamp installed should be something like 'c:/wamp/www/images/title.png'.

Ok, and what's the solution?

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: Including header from a different directory
« Reply #6 on: March 14, 2011, 01:46:32 PM »
Put a / in front of your images in your css, or src attributes. Basically where you have 'style/x.jpg' put '/style/x.jpg' and that should work.

*edit*
If that doesn't work if you paste some code that will help narrow down your issue.
« Last Edit: March 14, 2011, 01:49:22 PM by lolninja »

Offline mydas

  • Level 2
  • *
  • Posts: 4
  • Reputation: +0/-0
    • View Profile
Re: Including header from a different directory
« Reply #7 on: March 15, 2011, 05:19:07 AM »
It worked. Thank you very much.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal