[ PHP | JavaScript ]
Code Name: Image Randomizer
Added: 30/09/06 By: Ross This code will display a random image from the folder in which the code is placed in. To use, save the following code as "index.php" and link to it using standard html image tags: <img src="http://yourhost.com/path_to_folder" />
<?php
$image_folder = ".";
$imgArr = array();
$n = 0;
if($handle = opendir($image_folder)) {
while (false !== ($file = readdir($handle))) {
if(!preg_match('/thumbs/', $file) && preg_match('/.(gif|jpeg|jpg|png|bmp)$/', $file)) {
$imgArr[$n++] = $file;
}
}
$t = sizeof($imgArr)-1;
$random = mt_rand("0", $t);
$image_name = $imgArr[$random];
readfile($image_name);
}
?>
$image_folder = ".";
$imgArr = array();
$n = 0;
if($handle = opendir($image_folder)) {
while (false !== ($file = readdir($handle))) {
if(!preg_match('/thumbs/', $file) && preg_match('/.(gif|jpeg|jpg|png|bmp)$/', $file)) {
$imgArr[$n++] = $file;
}
}
$t = sizeof($imgArr)-1;
$random = mt_rand("0", $t);
$image_name = $imgArr[$random];
readfile($image_name);
}
?>