473,606 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

relative path / absolute path

Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn't an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.

--

Regards,

Jerry M. Gartner
Jun 18 '06 #1
19 5066
Jerry M. Gartner wrote:
Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn't an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.

If I understand you correctly, this is really a web server issue and is
handled by the 'Alias' function in Apache (other servers may call it
something else). This function allows you to set a path prefix - say,
/images - and have all references to an image resolve to the same place.

So in your code you would have <img src="/images/foo.gif"> and it would
resolve to /my_web/images/foo.gif regardless of where it was referenced
in your web document tree.

Aliases may also be used for css, javascript or any other commonly
shared code elements.

Hope this helps.
-david-

Jun 18 '06 #2
Jerry M. Gartner wrote:
Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons.

<snip>

I don't understand your problem. But, I prefer relative path and
had no issues with it.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jun 18 '06 #3
On Sun, 18 Jun 2006 10:24:20 GMT Jerry M. Gartner wrote:
[...] For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn't an issue but it is with relative paths.


Well to be on the safe side use absolute paths, this will definitely work.
To keep your scripts maintainable, make a configuration file where you will
put the paths in. E.g

config.php

$IMG_BASE_URL=" http://www.my-domain.com/images/";
and in your php files you write...

<img src="<?php echo $IMG_BASE_URL; ?>myImage001.jp g"/>

That way you can even change the image path later on (e.g. put all images
on a different server or load them with a script for load balancing or
whatever) and they will always work. I use this solution for my sites (well
in fact i use some method) like

function imglnk( $filename ) {
global $IMG_BASE_URL;
return $IMG_BASE_URL.$ filename;
}

and then
<img src="<?php imglnk( "myImage001.jpg " );?>/>

which isn't that kludgy and allows for arbitrary changes of the image
structure later on.

Best regards,
Jan Thomä
Jun 18 '06 #4
Jan Thomä wrote:
On Sun, 18 Jun 2006 10:24:20 GMT Jerry M. Gartner wrote:
[...] For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves
the
correct image path when opened under / but when x.php is read into a
file
under /dir the image no longer resolves, for obvious reasons. With
absolute paths, this isn't an issue but it is with relative paths.


Well to be on the safe side use absolute paths, this will definitely work.
To keep your scripts maintainable, make a configuration file where you
will put the paths in. E.g

<snip>
I would second this approach - in larger applications this has often been
one of the first 'include' files I've implemented, usually declaring the
path both in terms of its URL and the filesystem namespace:

// note - be consistent about trailing dir seperator
$image_url_pref ix="http://my.server.com/~colin/project/images/";
$image_file_pre fix="/home/colin/public_html/project/images/";
....

Of course, you'll then realise that the included file itself has a relative
and absolute path....but the advantage of this approach is that you can use
the path relative to one of the directories declared in the include_path
config file setting which removes the problem.

C.
Jun 18 '06 #5
Jerry M. Gartner wrote:
Greetings:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn't an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.


First of all, this isn't a PHP question - <img statements are html, whether
they're included in PHP or not. Now - if you were talking about include(),
require_once(), etc., you 'd be talking php.

The easiest way I've found is to just use absolute URL's for the images - i.e.

<img src="/images...">

Works everyplace on the site and you don't need to include extra files.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 18 '06 #6
js*******@attgl obal.net says...
Jerry M. Gartner wrote:

What is the best way to resolve paths within a document regardless of what
path it is opened under? For example: I have x.php and it contains <img
src="images..." >, (amongst other things, like php code), which resolves the
correct image path when opened under / but when x.php is read into a file
under /dir the image no longer resolves, for obvious reasons. With absolute
paths, this isn't an issue but it is with relative paths. Although I can
think of a kludge, or two, I figure that there is a more elegant solution.
Thanks in advance.


First of all, this isn't a PHP question - <img statements are html, whether
they're included in PHP or not. Now - if you were talking about include(),
require_once(), etc., you 'd be talking php.

The easiest way I've found is to just use absolute URL's for the images - i.e.

<img src="/images...">

Works everyplace on the site and you don't need to include extra files.


And in some circumstances (particularly with images) will result in more
efficient client-side caching.

GM
Jun 18 '06 #7
Message-ID: <rr************ *************** ***@comcast.com > from Jerry
Stuckle contained the following:
The easiest way I've found is to just use absolute URL's for the images - i.e.

<img src="/images...">

Works everyplace on the site and you don't need to include extra files.


I've always found a problem with that when working offline. How do you
get around that?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jun 18 '06 #8
Geoff Berrow wrote:
Message-ID: <rr************ *************** ***@comcast.com > from Jerry
Stuckle contained the following:

The easiest way I've found is to just use absolute URL's for the images - i.e.

<img src="/images...">

Works everyplace on the site and you don't need to include extra files.

I've always found a problem with that when working offline. How do you
get around that?


Don't know what problem you would have, unless you're trying to load the file
directly instead of through a webserver.

I always use a webserver for testing, though. Even have one going on my main
development system.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 19 '06 #9
Geoff Berrow wrote:
Message-ID: <rr************ *************** ***@comcast.com > from Jerry
Stuckle contained the following:
The easiest way I've found is to just use absolute URL's for the images -
i.e.

<img src="/images...">

Works everyplace on the site and you don't need to include extra files.


I've always found a problem with that when working offline. How do you
get around that?


Aah, easily "fixed": DocumentRoot "/"

:)

--
/Bent
Jun 19 '06 #10

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

Similar topics

4
9140
by: Joe Cybernet | last post by:
Is there any function for combining an absolute and a relative URL to result in an absolute URL? Like if I have http://www.domain.com and "../images/1.jpeg" it will evaluate to http://www.domain.com/images/1.jpeg. I know WinInet for windows has a function that does this called InternetCombineUrl, I just need the same function in PHP
3
3134
by: Peter Taurins | last post by:
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.
15
2893
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I found that there is an include file that references images: <img src = "/images/Header.gif" What worked correctly on the production server breaks on mine because of the absolute address "/images". I removed the absolute address and changed...
4
27717
by: Richard | last post by:
We are distributing a VS2003 solution to our customers that includes a .NET assembly (dll file) and a sample project for how to use the dll. The customer can then customize the sample or add a new project to the solution. The problem is that the customers cannot simply take the solution we distribute and build it. VS2003 is saving the reference to the dll as an fully qualified absolute path (not relative to the project), so after...
7
78628
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
6
11758
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data source=c:/Inetpub/MyApp/data/database.mdb" /> ...
8
3449
by: Daniel Serrano | last post by:
Hi, is it possible to use a relative path in a Connection string to access an Access database in a stand alone visual basic desktop application. All the examples that I have seen have absolute paths but my application could be a lot more flexible if it didn't depend on this. Thanks, Daniel Serrano
8
2595
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the path can take the form of the following: 1. /directory/images/xyz.gif (works fine) 2. http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif (doesn't work) 3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't work)
15
6449
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would make it much easier to slap modualar blocks of markup into page frameworks, which may change and so forth. And the few extra bytes, which even for a fairly large site would not amount to as many bytes as are in a fairly small low-res image, should...
0
7962
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8443
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8107
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
8315
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
6792
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...
0
5467
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
3945
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...
0
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.