|
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Γ€
Navigation:
[Reply to this message]
|