473,242 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Including files with images and relative/absolute addresses

Hi there.

I have an included file (header.php) that contanis a reference to a graphic.
If I stay at the root level, then I can control the relative path of the
image.
eg. images/imagename.jpg

However, if I include this file (header.php) in a lower level directory then
of course, I end up with no image displaying as the relative path is no
longer correct.

Currently I am using the following to provide an absolute path to the image.

$path = "http://".$_SERVER["HTTP_HOST"]."/images/";
$image = $path."imagename.jpg";
echo "<img src=\"$image\">";

This works fine, but looks klunky.

I would like to avoid specifying an absolute hardcoded path name so I can
load this function on any site I choose.

Any suggestions as to how to get images displaying when including a
header.php file in a lower lever directory?

Your assistance is appreciated.
Peter.

Jul 17 '05 #1
3 3112
Any suggestions as to how to get images displaying when including a
header.php file in a lower lever directory?


How about just

$path = "/images/";
$image = $path."imagename.jpg";

Wouldn't that achieve what you want? But if you need a
complete URL, then I think you're doing it just right
the way you are now.

But unless you are running a whole range of hosts that
all have the "/images/"-dir, I can't see what's wrong
with specifying a hardcoded, server specific path, since
you'll have to specify the "images"-part of it anyway?

--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}
Jul 17 '05 #2
Well, I learn something (fundamental) every day.
I didn't realise what the / did at the front.
And now I do.
Thanks muchly.
PWT
"Fred H" <se****@nospam.com> wrote in message
news:op**************@news.mimer.no...
Any suggestions as to how to get images displaying when including a
header.php file in a lower lever directory?


How about just

$path = "/images/";
$image = $path."imagename.jpg";

Wouldn't that achieve what you want? But if you need a
complete URL, then I think you're doing it just right
the way you are now.

But unless you are running a whole range of hosts that
all have the "/images/"-dir, I can't see what's wrong
with specifying a hardcoded, server specific path, since
you'll have to specify the "images"-part of it anyway?

--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}

Jul 17 '05 #3
Peter Taurins wrote:
Hi there.

I have an included file (header.php) that contanis a reference to a graphic.
If I stay at the root level, then I can control the relative path of the
image.
eg. images/imagename.jpg

However, if I include this file (header.php) in a lower level directory then
of course, I end up with no image displaying as the relative path is no
longer correct.

Currently I am using the following to provide an absolute path to the image.

$path = "http://".$_SERVER["HTTP_HOST"]."/images/";
$image = $path."imagename.jpg";
echo "<img src=\"$image\">";

This works fine, but looks klunky.

I would like to avoid specifying an absolute hardcoded path name so I can
load this function on any site I choose.

Any suggestions as to how to get images displaying when including a
header.php file in a lower lever directory?


I think that it is the best to always use absolute path. That way you
can move your files within folders, without breaking urls.

If your path is always the same you can always use:

$path = "/images/";
$image = $path."imagename.jpg";
echo "<img src=\"$image\">";
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Geoff Berrow | last post by:
If I'm working on a project, I'll usually create a folder to contain all the project files before uploading this to the root of the production server. The trouble is that if I do:...
7
by: mark | last post by:
I am designing a website at the moment and looking at the difference between relative and absolute url links which is driving me crazy! I would like to use relative paths, but it is proving very...
10
by: John | last post by:
I have a table with two rows. On the first row is a text box and in the second row is an image. I have set the table cellpadding to 0 and cellspacing to 0. The table is leaving extra spaces in the...
2
by: sylvian stone | last post by:
Hi, I'm trying to do something that has always been easy with tables - namely use a three column layout, and above the main layout, show three images - one on the absolute left, one on the absolute...
4
by: Bernie Raffe | last post by:
When I change the 'cookieless' flag in the WebConfig file to true, everything works fine on my local PC, but the images fail to appear when using the remote server. I specify my images...
2
by: John | last post by:
Hi all, I haven't a clue where to begin here (or more to the point - if it's even possible). I need to read the names of all the files inside a folder off my web site. The catch here is that...
4
by: dropdeadster | last post by:
Trying to line up a tic-tac-toe board type grid of images using style= tags to <img inside a table TD but it's not working, I get more like a set of steps, can I get an explanation of what's wrong...
2
by: vinit_mahajan99 | last post by:
Hello all, I want to align the images and controls at the bottom of a master page or at the right side. I tried to do it with the table but I was not successful. The image should be seen at...
2
by: gunnuk | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.