Reply to Re: relative path / absolute path

Your name:

Reply:


Posted by Jan Thomδ on 06/18/06 19:03

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Γ€

[Back to original message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация