Re: [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT']
| From: | John Nichel | Date: | Sun, 20 Feb 2005 18:56:17 +0000 |
| Subject: | Re: [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT'] | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-209085@lists.php.net to get a copy of this message | ||
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 DISPLAYThis 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