Forums

any help with this php syntax error (1 post)

  1. justprawn
    Member
    Posted 3 years ago #

    Can anyone help me correct this code as I am new and rubbish.

    '<?php
    function createThumbs ( $images/pee, $images/peethumbs, $thumbWidth20 );

    // open the directory
    $dir = opendir( $images/pee );

    // loop through it, looking for any/all JPG files:
    while (false !== ($fname = readdir( $dir ))) {
    // parse path for the extension
    $info = pathinfo($images/pee . $fname);
    // continue only if this is a JPEG image
    if ( strtolower($info['extension']) == 'jpg' )
    {
    echo "Creating thumbnail for {$fname}
    ";

    // load image and get image size
    $img = imagecreatefromjpeg( "{$image/pee}{$fname}" );
    $width = imagesx( $img );
    $height = imagesy( $img );

    // calculate thumbnail size
    $new_width = $20;
    $new_height = floor( $height * ( $20 / $width ) );

    // create a new temporary image
    $tmp_img = imagecreatetruecolor( $new_width, $new_height );

    // copy and resize old image into new image
    imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

    // save thumbnail into a file
    imagejpeg( $tmp_img, "{$images/peethumbs}{$fname}" );
    }
    }
    // close the directory
    closedir( $dir );
    }
    // call createThumb function and pass to it as parameters the path
    // to the directory that contains images, the path to the directory
    // in which thumbnails will be placed and the thumbnail's width.
    // We are assuming that the path will be a relative path working
    // both in the filesystem, and through the web for links
    createThumbs("upload/images/pee","upload/thumbs/images/peethumbs",100);
    ?>
    <?php
    function createGallery( $images/pee, $images/peethumbs );
    {
    echo "Creating gallery.html
    ";

    $output = "<html>";
    $output .= "<head><title>Thumbnails</title></head>";
    $output .= "<body>";
    $output .= "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">";
    $output .= "<tr>";

    // open the directory
    $dir = opendir( $images/peethumbs );

    $counter = 0;
    // loop through the directory
    while (false !== ($fname = readdir($dir)))
    {
    // strip the . and .. entries out
    if ($fname != '.' && $fname != '..')
    {
    $output .= "<td valign=\"middle\" align=\"center\">";
    $output .= "<img src=\"{$images/peethumbs}{$fname}\" border=\"0\" />";
    $output .= "
    </td>";

    $counter += 1;
    if ( $counter % 4 == 0 ) { $output .= "</tr><tr>"; }
    }
    }
    // close the directory
    closedir( $dir );

    $output .= "</tr>";
    $output .= "</table>";
    $output .= "</body>";
    $output .= "</html>";

    // open the file
    $fhandle = fopen( "gallery.html", "w" );
    // write the contents of the $output variable to the file
    fwrite( $fhandle, $output );
    // close the file
    fclose( $fhandle );
    }
    // call createGallery function and pass to it as parameters the path
    // to the directory that contains images and the path to the directory
    // in which thumbnails will be placed. We are assuming that
    // the path will be a relative path working
    // both in the filesystem, and through the web for links
    createGallery("upload/images/pee","upload/thumbs/images/peethumbs");
    ?>'

    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags