Random ImageDescription
Display a random image from a directory. Tutorial<?php
$dir=opendir("images/");
//This is the directory route to the folder
$directory="images/";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on
$pattern=".(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<img src=\"$directory$image[$randNum]\" $size[3]>";
?>
|