Image gallery preupload script from sitepoint giving me a ton of syntax errors

I read through the image gallery tutorial here on sitepoint, but right as I start building the prupload form, I get at least 15 syntax errors starting on line 15 and the form won’t display, I understand this was built in 2003, but I am still so new to php that I can’t find the errors, here is the code from the tutorial:

<?php    
  include 'config.inc.php';    
    
  // initialization    
  $photo_upload_fields = '';    
  $counter = 1;    
    
  // If we want more fields, then use, preupload.php?number_of_fields=20    
  $number_of_fields = (isset($_GET['number_of_fields'])) ?    
    (int)($_GET['number_of_fields']) : 5;    
    
  // Firstly Lets build the Category List    
  $result = mysql_query('SELECT category_id,category_name FROM gallery_category');    
  while($row = mysql_fetch_array($result)) {    
    $photo_category_list .= <<<__HTML_END    
<option value="$row[0]">$row[1]</option>\
    
__HTML_END;    
  }    
  mysql_free_result( $result );      
    
  // Lets build the Image Uploading fields    
  while($counter <= $number_of_fields) {    
    $photo_upload_fields .= <<<__HTML_END    
<tr><td>    
  Photo {$counter}:    
  <input name="photo_filename[]"    
type="file" />    
</td></tr>    
<tr><td>    
  Caption:    
  <textarea name="photo_caption[]" cols="30"    
    rows="1"></textarea>    
</td></tr>    
__HTML_END;    
    $counter++;    
  }    
    
  // Final Output    
  echo <<<__HTML_END    
<html>    
<head>    
<title>Lets upload Photos</title>    
</head>    
<body>    
<form enctype="multipart/form-data"    
  action="upload.php" method="post"    
  name="upload_form">    
  <table width="90%" border="0"    
    align="center" style="width: 90%;">    
    <tr><td>    
      Select Category    
      <select name="category">    
      $photo_category_list    
      </select>    
    </td></tr>    
    <! - Insert the image fields here -->    
    $photo_upload_fields    
    <tr><td>    
      <input type="submit" name="submit"    
        value="Add Photos" />    
    </td></tr>    
  </table>    
</form>    
</body>    
</html>    
__HTML_END;    
?>

so any help I can get with this would be appreciated

Ok, I got everything to work almost. The tutorial was great, I just did one little mistake and it wouldn’t work right.

But now the problem I am having is that it won’t read the $images_dir at all in the upload.php scripting. I have made a photos folder on the server, chmod it 777, and the php pages are residing in the same directory where the photos dir is. I can’t figure out why, I have tried the little that I know about php to get reading it, but it won’t, here is the code:


&lt;?php
	include("connect.php");

	// initialization
	$result_final = "";
	$counter = 0;
	
	// List of our known photo types
	$known_photo_types = array( 
						'image/pjpeg' =&gt; 'jpg',
						'image/jpeg' =&gt; 'jpg',
						'image/gif' =&gt; 'gif',
						'image/bmp' =&gt; 'bmp',
						'image/x-png' =&gt; 'png'
					);
	
	// GD Function List
	$gd_function_suffix = array( 
						'image/pjpeg' =&gt; 'JPEG',
						'image/jpeg' =&gt; 'JPEG',
						'image/gif' =&gt; 'GIF',
						'image/bmp' =&gt; 'WBMP',
						'image/x-png' =&gt; 'PNG'
					);

	// Fetch the photo array sent by preupload.php
	$photos_uploaded = $_FILES['photo_filename'];

	// Fetch the photo caption array
	$photo_caption = $_POST['photo_caption'];

	while( $counter &lt;= count($photos_uploaded) )
	{
		if($photos_uploaded['size'][$counter] &gt; 0)
		{
			if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
			{
				$result_final .= "File ".($counter+1)." is not a photo&lt;br /&gt;";
			}
			else
			{
				mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
				$new_id = mysql_insert_id();
				$filetype = $photos_uploaded['type'][$counter];
				$extention = $known_photo_types[$filetype];
				$filename = $new_id.".".$extention;

				mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

				// Store the orignal file
				copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);

				// Let's get the Thumbnail size
				$size = GetImageSize( $images_dir."/".$filename );
				if($size[0] &gt; $size[1])
				{
					$thumbnail_width = 100;
					$thumbnail_height = (int)(100 * $size[1] / $size[0]);
				}
				else
				{
					$thumbnail_width = (int)(100 * $size[0] / $size[1]);
					$thumbnail_height = 100;
				}
			
				// Build Thumbnail with GD 1.x.x, you can use the other described methods too
				$function_suffix = $gd_function_suffix[$filetype];
				$function_to_read = "ImageCreateFrom".$function_suffix;
				$function_to_write = "Image".$function_suffix;

				// Read the source file
				$source_handle = $function_to_read ( $images_dir."/".$filename ); 
				
				if($source_handle)
				{
					// Let's create an blank image for the thumbnail
				     	$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );
				
					// Now we resize it
			      	ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );
				}

				// Let's save the thumbnail
				$function_to_write( $destination_handle, $images_dir."/tb_".$filename );
				ImageDestroy($destination_handle );
				//

				$result_final .= "&lt;img src='".$images_dir. "/tb_".$filename."' /&gt; File ".($counter+1)." Added&lt;br /&gt;";
			}
		}
	$counter++;
	}

	// Print Result
echo &lt;&lt;&lt;__HTML_END

&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Photos uploaded&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	$result_final
&lt;/body&gt;
&lt;/html&gt;

__HTML_END;
?&gt;

Any suggestions?