How can I get absolute path for images?

I’m working on an email template system where my client will go to a page and copy & paste the source code into their crm system.

I’m trying to find a way to automatically replace the image path without the use of echo if possible.

I’ve figured this out already with this script:

[php]<?
function GetFileDir($php_self){
$filename = explode("/", $php_self); // THIS WILL BREAK DOWN THE PATH INTO AN ARRAY
for( $i = 0; $i < (count($filename) - 1); ++$i ) {
$filename2 .= $filename[$i].’/’;
}
return $filename2;
}
?>[/php]

But I don’t wanna have to go in and put

[php]<?php echo GetFileDir("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>[/php]

before all the image paths.

So basically anywhere that src=“images/whatever.jpg” is listed it will replace “images/” with “http://www.mydomain.com/images/whatever.jpg

is it possible to do this without having to place code before “images” ?

Hi Derek,

PHP has magical constant called FILE which can return full path and file name of the file. Refer to PHP manual for more info http://php.net/manual/en/language.constants.predefined.php

I hope this helps… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service