473,769 Members | 7,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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."imagenam e.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 3142
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."imagenam e.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.sa y("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.mim er.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."imagenam e.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.sa y("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."imagenam e.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."imagenam e.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
1412
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: include('/myfile.php') this looks at the root of local host, as it should and not at the root of the working directory. It means that if I want to use absolute links, I have to change them before I upload. Or am I missing something blindingly obvious?
7
2837
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 restrictive as to how I design the file structure when it comes to including files. I currently have something like below: folder1 folder2 images ---image1.gif
10
7855
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 rows on the top and bottom of the picture and image. I need to make the height of the rows to be the same as the textbox and image. How do I do this? I have tried even setting the height of the table and all the <td> and <tr> tags to 1 but have...
2
5706
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 right, and one in the middle. The one in the middle needs to be centered, as various browsers display slightly differently. However, using the CSS and code below, either the first image is not shown (IE) or the right image is shown below...
4
2507
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 throughout using a relative directory structure, such as 'images/topbanner.jpg'. I tried changing this to ~/images/topbanner.jpg and .../images/topbanner.jpg, but this didn't work locally so I didn't even bother trying it out remotely. Tthe problem...
2
1731
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 I don't know the absolute path here (C:\inetpub\whatever\whatever\etc...) as it could be on any drive at my ISP. Is there a way to retrieve a list of these files by somehow using the
4
4067
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 with this and how to do it correctly?: <table border="1"> <tr> <td valign="top" align="left">
2
2489
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 the bottom of the page. Please reply....
2
2040
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 http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>WELCOME TO HEMA CREATIVE HOUSE</title> <style type="text/css"> <!-- @import url("css/IDESIGN 1.css"); @import url("css/IDESIGN.2.css"); body {
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.