|
Posted by Dave on 02/20/05 20:22
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/
[Back to original message]
|