This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-14 21:55:53

dontbombiraq
Scratcher
Registered: 2009-08-26
Posts: 100+

PHP Help

I'm having a problem with some PHP. It gives me a T_STRING error, but I can't find any problems.

Code:

 <?php

 $folder = '.';

    $extList = array();
    
    $extList['gif'] = 'image/gif';
    
    $extList['jpg'] = 'image/jpeg';
    
    $extList['jpeg'] = 'image/jpeg';
    
    $extList['png'] = 'image/png';



 $img = null;



 if (substr($folder,-1) != '/') {
    
     $folder = $folder.'/';


 }



 if (isset($_GET['img'])) {
    
      $imageInfo = pathinfo($_GET['img']);
    
      if (
        
          isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        
          file_exists( $folder.$imageInfo['basename'] )
    
      ) {
        
          $img = $folder.$imageInfo['basename'];
    
      }

 } else {
    
      $fileList = array();

      $handle = opendir($folder);

      while ( false !== ( $file = readdir($handle) ) ) {

          $file_info = pathinfo($file);

          if (
            
              isset( $extList[ strtolower( $file_info['extension'] ) ] )

          ) {

            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>

http://i39.tinypic.com/259j2mu.png

Offline

 

#2 2012-12-14 22:02:58

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: PHP Help

What line does it say?


http://i.imgur.com/BAEgGDL.png

Offline

 

#3 2012-12-14 22:55:52

dontbombiraq
Scratcher
Registered: 2009-08-26
Posts: 100+

Re: PHP Help

It doesn't matter, there was no issue with the line.
But it was 5.


http://i39.tinypic.com/259j2mu.png

Offline

 

#4 2012-12-14 22:59:52

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: PHP Help

dontbombiraq wrote:

It doesn't matter, there was no issue with the line.
But it was 5.

Strange.  I get a yellow image when I run it.


http://i.imgur.com/BAEgGDL.png

Offline

 

#5 2012-12-14 23:01:25

dontbombiraq
Scratcher
Registered: 2009-08-26
Posts: 100+

Re: PHP Help

It's supposed to randomly display images from your directory.


http://i39.tinypic.com/259j2mu.png

Offline

 

Board footer