jan_dembowski

rotate.php

Apr 6th, 2012
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. /*
  3. By Matt Mullenweg > http://photomatt.net
  4. Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
  5. Latest version always at:
  6.  
  7. http://photomatt.net/scripts/randomimage
  8.  
  9. */// Make this the relative path to the images, like "../img" or "random/images/".
  10. // If the images are in the same directory, leave it blank.
  11. $folder = 'images/';
  12.  
  13. // Space seperated list of extensions, you probably won't have to change this.
  14. $exts = 'jpg jpeg png gif';
  15.  
  16. $files = array(); $i = -1; // Initialize some variables
  17. if ('' == $folder) $folder = './';
  18.  
  19. $handle = opendir($folder);
  20. $exts = explode(' ', $exts);
  21. while (false !== ($file = readdir($handle))) {
  22. foreach($exts as $ext) { // for each extension check the extension
  23. if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
  24. $files[] = $file; // it's good
  25. ++$i;
  26. }
  27. }
  28. }
  29. closedir($handle); // We're not using it anymore
  30. mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
  31. $rand = mt_rand(0, $i); // $i was incremented as we went along
  32.  
  33. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  34. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  35. header('Location: '.$folder.$files[$rand]); // Voila!
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment