Re: [NEWBIE] Confused about usage of $_SERVER['DOCUMENT_ROOT']

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andre, Mirco, BDT,

  Thank you for your responses.

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

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.

function random_img($dir,$type='random')
{
global $errors,$seed;

if (is_dir($dir)) {

$fd = opendir($dir); $images = array();

while (($part = @readdir($fd)) == true) {

         if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
             $images[] = $part;
         }
     }

   // adding this in case you want to return the image array
   if ($type == 'all') return $images;

if ($seed !== true) {
mt_srand ((double) microtime() * 1000000);
$seed = true;
}
$key = mt_rand (0,sizeof($images)-1);


   return $dir . $images[$key];

 } else {
     $errors[] = $dir.' is not a directory';
     return false;
 }
}

--
Dave Gutteridge
dave@xxxxxxxxxxxxxxx/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux