Skip to content

Instantly share code, notes, and snippets.

@benjamingwynn
Created October 19, 2012 15:12
Show Gist options
  • Save benjamingwynn/3918749 to your computer and use it in GitHub Desktop.
Save benjamingwynn/3918749 to your computer and use it in GitHub Desktop.
<?php
$folder = 'benjaminimage/';
$exts = 'png';
$files = array(); $i = -1;
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) {
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]);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment