Put this file - call it randomimages.php, in the folder with the images in it:
PHP Code:
<!DOCTYPE html>
<html>
<head>
<title>My Random Images</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
function randomimages(){
$dirname = isset($_REQUEST['dir'])? $_REQUEST['dir'] : './';
$numimages = isset($_REQUEST['num'])? $_REQUEST['num'] : 20;
$pattern = '#\.(jpg|jpeg|png|gif|bmp)$#i';
$files = array();
if($handle = opendir($dirname)){
while(($file = readdir($handle)) !== false){
if(preg_match($pattern, $file)){
array_push($files, "\t<img src='" . $dirname . $file . "' alt='' />");
}
}
closedir($handle);
shuffle($files);
}
return implode("\n", array_slice($files, 0, $numimages)) . "\n";
}
echo randomimages();
?>
</body>
</html>
Alternatively you can put it anywhere and set the folder it will pull images from by linking to it from another page and giving it a query, example link to it:
HTML Code:
<a href="randomimages.php?dir=./pics/">Random Images</a>
Bookmarks