PDA

View Full Version : get full html path to a file using php


Billy T
01-04-2007, 05:35 AM
Hey all

I'm looking for a way to get the full html path to a file using php

for example

say I have a php that has a reference to a file on my server. I can get the real path such as

/home/me/public/content/file.jpg

but how can I get

http://www.mydomain.com/content/file.jpg

?


Thanks in advance

Billy T
01-04-2007, 10:36 AM
never mind

CyanBlue
01-04-2007, 01:58 PM
Never say never mind but post the solution, dang it... :runaway: :p

sickscripts
01-04-2007, 02:57 PM
Yeah, I'd like to know the solution. Some of my hosts will give this or I can find it easlily, while other hosting providers have not made this easy.

Billy T
01-04-2007, 10:49 PM
well I would have posted it but the solutions appears to be fairly specific to my host

here it is anyway

the php $GLOBALS['DOCUMENT_ROOT'] was returning a slightly different path to dirname()

so I used a regular expression that would catch all variations of the document root (this is used for multiple domains on teh same host) and remove that string from dirname()

then I add the domain to the start of the string that is left over from the dirname to build the full http path to the file


//the consistent component in the document root string is '-www'
$folderPath= dirname(__FILE__);
$parts=preg_split('/-w{3}/',$folderPath,2);
$filePath='http://www.'.$GLOBALS['HTTP_HOST'] . $parts[1];


Hope that helps