the latest
October 20, 2008 New Backup Script has been launched. Some house keeping has been done around the site and we have a few new items to be added soon.

the greatest

» Backup Script
» Contact Script
» PHP Includes
» Image Gallery

Random Image

Description

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]>";
?>


Home : Services : Scripts : Tutorials : Hosting : Contact