Advertisement
ircghetto

Untitled

May 1st, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.     $folder = '.';
  3.     $extList = array();
  4.     $extList['gif'] = 'image/gif';
  5.     $extList['jpg'] = 'image/jpeg';
  6.     $extList['jpeg'] = 'image/jpeg';
  7.     $extList['png'] = 'image/png';
  8.    
  9.    
  10. $img = null;
  11.  
  12. if (substr($folder,-1) != '/') {
  13.     $folder = $folder.'/';
  14. }
  15.  
  16. if (isset($_GET['img'])) {
  17.     $imageInfo = pathinfo($_GET['img']);
  18.     if (
  19.         isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
  20.         file_exists( $folder.$imageInfo['basename'] )
  21.     ) {
  22.         $img = $folder.$imageInfo['basename'];
  23.     }
  24. } else {
  25.     $fileList = array();
  26.     $handle = opendir($folder);
  27.     while ( false !== ( $file = readdir($handle) ) ) {
  28.         $file_info = pathinfo($file);
  29.         if (
  30.             isset( $extList[ strtolower( $file_info['extension'] ) ] )
  31.         ) {
  32.             $fileList[] = $file;
  33.         }
  34.     }
  35.     closedir($handle);
  36.  
  37.     if (count($fileList) > 0) {
  38.         $imageNumber = time() % count($fileList);
  39.         $img = $folder.$fileList[$imageNumber];
  40.     }
  41. }
  42.  
  43. if ($img!=null) {
  44.     $imageInfo = pathinfo($img);
  45.     $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
  46.     header ($contentType);
  47.     readfile($img);
  48. } else {
  49.     if ( function_exists('imagecreate') ) {
  50.         header ("Content-type: image/png");
  51.         $im = @imagecreate (100, 100)
  52.             or die ("Cannot initialize new GD image stream");
  53.         $background_color = imagecolorallocate ($im, 255, 255, 255);
  54.         $text_color = imagecolorallocate ($im, 0,0,0);
  55.         imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
  56.         imagepng ($im);
  57.         imagedestroy($im);
  58.     }
  59. }
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement