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 19 5036
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-
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/
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.jpg"/>
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ä
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_prefix="http://my.server.com/~colin/project/images/";
$image_file_prefix="/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.
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*******@attglobal.net
================== js*******@attglobal.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
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/
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*******@attglobal.net
==================
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
Jan Thomä wrote: 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/";
If you have ever had to use a reverse-proxy on a web application, you'd
realize what an evil absolute paths are.
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?
Glad to see professor after long time; hope economy is fine
there. I don't understand what sort of problem are you facing. But, in
HTML instead of using <img src="/images/..." />, if you use <img
src="images/..." /> you'll be better off.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
On Sun, 18 Jun 2006 20:18:19 -0400, Jerry Stuckle wrote: 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.
Exactly, particularly as this is a PHP newsgroup - the next complaint will
be "when I work offline, my PHP doesn't execute, it just prints the
source code" :-)
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer http://www.gphpedit.org | PHP editor for Gnome 2 http://www.andyjeffries.co.uk | Personal site and photos
R. Rajesh Jeba Anbiah wrote: 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?
Glad to see professor after long time; hope economy is fine there. I don't understand what sort of problem are you facing. But, in HTML instead of using <img src="/images/..." />, if you use <img src="images/..." /> you'll be better off.
-- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Doesn't validate in HTML 4.01 (strict or transitional).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
I understand that this is a php group. Thus the post. The question is
relevant to php as I am writing a rather ugly php application - the post
from Jan was just what I was looking for. I appreciate everyone's input.
--
Regards,
Jerry M. Gartner
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:rr******************************@comcast.com. .. 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*******@attglobal.net ==================
Jerry M. Gartner wrote: I understand that this is a php group. Thus the post. The question is relevant to php as I am writing a rather ugly php application - the post from Jan was just what I was looking for. I appreciate everyone's input.
So, what's your PHP question? The only one you asked was about the <img> tag -
which is HTML, not PHP.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry Stuckle wrote:
<snip> Glad to see professor after long time; hope economy is fine there. I don't understand what sort of problem are you facing. But, in HTML instead of using <img src="/images/..." />, if you use <img src="images/..." /> you'll be better off.
Doesn't validate in HTML 4.01 (strict or transitional).
So, instead of "images/..", if we use "/images/.." will it
validate?
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
R. Rajesh Jeba Anbiah wrote: Jerry Stuckle wrote: <snip>
Glad to see professor after long time; hope economy is fine there. I don't understand what sort of problem are you facing. But, in HTML instead of using <img src="/images/..." />, if you use <img src="images/..." /> you'll be better off.
Doesn't validate in HTML 4.01 (strict or transitional).
So, instead of "images/..", if we use "/images/.." will it validate?
-- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
The problem is:
<img src="images/..." />
^
This is valid for xml but not html.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Jerry Stuckle wrote: R. Rajesh Jeba Anbiah wrote:
<snip> Glad to see professor after long time; hope economy is fine there. I don't understand what sort of problem are you facing. But, in HTML instead of using <img src="/images/..." />, if you use <img src="images/..." /> you'll be better off.
Doesn't validate in HTML 4.01 (strict or transitional).
So, instead of "images/..", if we use "/images/.." will it validate?
The problem is:
<img src="images/..." /> ^
This is valid for xml but not html.
LOL.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
R. Rajesh Jeba Anbiah wrote: Jerry Stuckle wrote:
R. Rajesh Jeba Anbiah wrote:
<snip>
> Glad to see professor after long time; hope economy is fine >there. I don't understand what sort of problem are you facing. But, in >HTML instead of using <img src="/images/..." />, if you use <img >src="images/..." /> you'll be better off.
Doesn't validate in HTML 4.01 (strict or transitional).
So, instead of "images/..", if we use "/images/.." will it validate?
The problem is:
<img src="images/..." /> ^
This is valid for xml but not html.
LOL.
-- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Try running it through an HTML validator. Or show me exactly where in the HTML
specs it says this is valid.
You can't - because it's not valid.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
...
|
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...
|
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...
|
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!
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
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"....
|
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...
|
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...
|
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 =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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: 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: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
| |