Random Images
Found this nice little php snippet lying around in my misc script folder. Its relatively easy to install and use. I don’t know the author of the script, so if you know, give me a whisper and I will add the credits.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
< ?php
//make this the relative path to the images, like "../img" or "random/images/".
//if the images are in the same directory, leave it blank.
$folder = '../images/random/';
//space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1;
if('' == $folder) {
$folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
//for each extension check the extension
foreach($exts as $ext) {
//faster than ereg, case insensitive
if (preg_match('/\.'.$ext.'$/i', $file, $test)) {
$files[] = $file;
++$i;
}
}
}
}
closedir($handle);
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i);
header('Location: '.$folder.$files[$rand]);
?> |









Recent Comments