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

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

« previous php.general (#209084) next »