A gallery script problem

I came accross this script a few days ago, and with a bit of messing around, most things worked.

However, the most important bit, the actual uploading and resizing into thumbnails doesn’t!

The stuff gets added to the database, but the files don’t! can anyone see what the problem may be?

Here’s the upload code:

 <?php session_start();

$goback = "/gallery.php";

if($_SESSION['loggedin'] != 1)
{
header("Location:$goback");
exit;
}
?>

<?php
	
	include('connect.php');

	// initialization
	$result_final = "";
	$counter = 0;

	// List of our known photo types
	$known_photo_types = array( 'image/pjpeg' => 'jpg','image/jpeg' => 'jpg','image/gif' => 'gif','image/bmp' => 'bmp','image/x-png' => 'png');
	
	// GD Function List
	$gd_function_suffix = array( 'image/pjpeg' => 'JPEG','image/jpeg' => 'JPEG','image/gif' => 'GIF','image/bmp' => 'WBMP','image/x-png' => '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 <= count($photos_uploaded) )
	{
		if($photos_uploaded['size'][$counter] > 0)
		{
		 if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
			{
		 	$result_final .= "File ".($counter+1)." is not a photo<br />";
			}
			else
			{
		 	mysql_query( "INSERT INTO photos(`photo_name`, `photo_caption`, `photo_album`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['album'])."')" );
				$new_id = mysql_insert_id();
				$filetype = $photos_uploaded['type'][$counter];
				$extention = $known_photo_types[$filetype];
				$filename = $new_id . "." . $extention;

		 	mysql_query( "UPDATE photos SET photo_name='".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] > $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;
				}
			
		$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 a blank image for the thumbnail
			 $destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);

			 // Now we resize it
			 ImageCopyResampled($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);

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

	// Print Result

echo <<<__HTML_END

<html>
<head>
	<title>Photos uploaded</title>
</head>
<body>
	$result_final
</body>
</html>

__HTML_END;
?>

and the connect.php file that goes with it:

 <?php

$conn = mysql_connect('localhost', 'astsite', 'astmoor');
  
mysql_select_db('Astmoor', $conn) or die('Could not select database');

$images_dir = '/gallery/photos';

?>

this is running locally, on my computer, so no CHMOD problmes, file permissions etc

oh, and the tutorial scripts here if you want to see it