Advertisement
Guest User

Random Sig - tooti

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