mkv

php image rotator

mkv
Sep 20th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=UTF-8');
  3. header('Cache-Control: no-cache, must-revalidate');
  4. header('Expires: Sat, 09 Jan 2009 09:09:09 GMT');
  5.  
  6. // the folder to read pictures from
  7. // default: '..'  (parent folder)
  8. $folder = '..';
  9.  
  10. // the picture formats to support
  11. $formats = array(
  12.         'jpg'  => 'image/jpg',
  13.         'jpeg' => 'image/jpeg',
  14.         'png'  => 'image/png',
  15.         'gif'  => 'image/gif'
  16. );
  17.  
  18. if (substr($folder, -1) != '/')
  19. {
  20.         $folder .= '/';
  21. }
  22. $image = '';
  23. $files = array();
  24. $h = opendir($folder);
  25. while (false !== ($file = readdir($h)))
  26. {
  27.         $ext = '';
  28.         $info = pathinfo($file);
  29.         if (isset($info['extension']))
  30.         {
  31.                 $ext = $info['extension'];
  32.         }
  33.         if (isset($formats[strtolower($ext)]))
  34.         {
  35.                 $files[] = $file;
  36.         }
  37. }
  38. closedir($h);
  39. if (count($files) > 0)
  40. {
  41.         $image = time() % count($files);
  42.         $image = $folder.$files[$image];
  43. }
  44. if (strlen($image) <3 )
  45. {
  46.         die('no pix (sorry bro)');
  47. }
  48.  
  49. // Setting the picture header
  50. $info = pathinfo($image);
  51. $ext = $info['extension'];
  52. $mime = $formats[strtolower($ext)];
  53. header('Content-Type: ' . $mime);
  54.  
  55. // Flushing the image to output
  56. set_time_limit(5);
  57. $image = @fopen($image, 'rb');
  58. while (!feof($image))
  59. {
  60.         print(@fread($image, 8192));
  61.         ob_flush();
  62.         flush();
  63. }
  64.  
  65. // the missing PHP closing tag
  66. // (questionmark and greater-than sign)
  67. // is intentional to prevent image corruption
Advertisement
Add Comment
Please, Sign In to add comment