Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 28 lines (27 sloc) 0.96 kB
642c326 Intial Code
jeremyclark13 authored
1 <?php
2 /*
3 By Matt Mullenweg > http://ma.tt
4 Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
5 Latest version always at:
6 http://ma.tt/scripts/randomimage
7 */
8 $folder = './images/headers/';
9 // Space seperated list of extensions, you probably won't have to change this.
10 $exts = 'jpg jpeg png gif';
11 $files = array(); $i = -1; // Initialize some variables
12 if ('' == $folder) $folder = './';
13 $handle = opendir($folder);
14 $exts = explode(' ', $exts);
15 while (false !== ($file = readdir($handle))) {
16 foreach($exts as $ext) { // for each extension check the extension
17 if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
18 $files[] = $file; // it's good
19 ++$i;
20 }
21 }
22 }
23 closedir($handle); // We're not using it anymore
24 mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
25 $rand = mt_rand(0, $i); // $i was incremented as we went along
26 header('Location: '.$folder.$files[$rand]); // Voila!
27 ?>
Something went wrong with that request. Please try again.