This code will display a picture at random from the specified directory.
The $file_dir variable is the relative path to the pictures folder.
The $f_type variable is the extension of the image files that you wish to display. In the example, all the files that I wish to display end in "tm.jpg"
Finally, you must ensure that the second argument in the explode function matches the number of characters specified in the extension variable. In my example the digit is 6 because my extension (tm.jpg) has 6 characters.
PHP Example :
<?
// #### RANDOM PIC #########################################
$thumbstring = '';
$file_dir="pics/a10"; // DIRECTORY WITH THE PICS
$f_type="tm.jpg"; // FILE EXTENSION YOU WISH TO DISPLAY
$dir=opendir($file_dir);
while ($file=readdir($dir))
{
if ($file != "." && $file != "..")
{
$extension=substr($file,-6); // THIS DIGIT MUST MATCH THE NUMBER OF CHARACTERS SPECIFIED IN THE FILE EXTENSION ABOVE
if($extension == $f_type)
{
$thumbstring .= "$file|";
}
}
}
srand((double)microtime()*1000000);
$arry_txt = explode("|" , $thumbstring);
echo "<img src="".$file_dir."/".$arry_txt[rand(0, sizeof($arry_txt) -1)]."">";
// #### END RANDOM PIC #########################################
?>