Weather Commerce
CAM - Random Image
{kl_php}
// print a random image. Don't forget ending slash!
// setting $type to 'all' will return all images.
function getRandomImage($dir,$type='random')
{
global $errors;
if (is_dir($dir)) {
$fd = opendir($dir);
$images = array();
while (($part = @readdir($fd)) == true) {
clearstatcache();
if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
if ( !(eregi("_thb_",$part)) ) {
$images[] = $part;
}
}
}
// adding this in case you want to return the image array
if ($type == 'all') { return $images; }
// Be sure to call srand() once per script
srand ((double) microtime() * 1000000);
$key = rand (0,sizeof($images)-1);
return $dir . $images[$key];
} else {
$errors[] = $dir.' is not a directory';
return false;
}
}
global $my;
if (!$my->id) {
echo "';
$randomimage = getRandomImage('images/stories/easygallery/18/');
print '
';
echo ' ';
};
{/kl_php}
This image is restricted to our Members.
Please register and/or log in to view.
"; } else { echo '