tags:

views:

45

answers:

2

I need to create thumbnails for all the jpg images in a folder. When I compile it, the error message pops out:

Parse error: syntax error, unexpected T_VARIABLE in /volume1/web/CAL1/thumb.php on line 6

and here is my code:

<?php
    $pathToImages = "./images/";
    $pathToThumbs = "./images/thumbnails/";
    $thumbWidth = 110;
  
    $dir = opendir($pathToImages);

    while (false != ($fname = readdir($dir))) {
            $info = pathinfo($pathToImages . $fname);
            if ( strtolower($info['extension']) == 'jpg' ) {
                echo "Creating thumbnail for {$fname} <br />";
            $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
                $width = imagesx( $img );
                $height = imagesy( $img );
            $new_width = $thumbWidth;
                $new_height = floor( $height * ( $thumbWidth / $width ) );
            $tmp_img = imagecreatetruecolor( $new_width, $new_height );
            imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
            imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
            }
    }

    closedir( $dir );
?>

I cannot find where does the error come from. Can anyone help me please? thanks in advance.

A: 

maybe an "hidden" encoding problem; try to put the code in an editor with only text (like notepad) and then, copy that code in the editor back to your code. Maybe that helps you out (or try to write lines 4 to 8 all new)

Sascha Presnac
A: 

try removing any white spaces across <?php and ?> tags

Maulik Vora