473,397 Members | 2,116 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,397 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 3120
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.