Dave wrote:
Here is some test code
<?php
echo "<img src=\"inline/topimage.jpg\" >";
echo "<img src=\"/inline/topimage.jpg\" >";
echo "<img src=\"" . $_SERVER['DOCUMENT_ROOT'] . "/inline/topimage.jpg\" >";
?>:


Theoretically, they should all output the same image. However:

<img src="inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/inline/topimage.jpg" > ->IMAGE DISPLAYS
<img src="/home/sites/sitexxx/web/inline/topimage.jpg" > IMAGE DOES NOT DISPLAY

This is the expected result. $_SERVER['DOCUMENT_ROOT'] is just that. The path from root of the _filesystem_ to where Apache's document root is. This is not Apache's document root.


What you're looking for above is something like $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME']. I'd stick with HTTP_HOST, something like this...

echo ( "<img src=\"http://"; . $_SERVER['HTTP_HOST'] . "/path/to/image.jpg\">";

Of course, the first instance only works if the script is in the correct place relative to the /inline directory.

However, the second case fails if I use it in the following function (assuming I specify $dir as "/inline"). It returns a false result, as if it couldn't find the directory.

This is where you would want to use DOCUMET_ROOT.

--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to