Ok, I have the following code now.... however, a thumbnail is not being created at all, but the original photo is uploading. Just no thumbnail. Please help... Try it out here:
http://www.zero1productions.com/sitepointgallery/preupload.php
view your results here:
http://www.zero1productions.com/sitepointgallery/viewgallery.php
upload.php:
include("config.inc.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'
);
// 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 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);
//imagemagick
$path_imagemagick="/usr/bin/";
$norm_dir = $_SERVER['DOCUMENT_ROOT'] . "/photos/";
$thumb_dir = $_SERVER['DOCUMENT_ROOT'] . "/photos/";
$max_width = 160;
$max_height = 120;
$max_width1 = 500;
$max_height1 = 500;
umask(000);
// Path to original and paths to save to
$path_picture = $filename;
$path_norm = "$norm_dir$filename";
$path_thumb = "$thumb_dir$filename";
// Resize and save pictures in correct directorys
$ok0 = shell_exec($path_imagemagick."convert -size $max_width1
$path_picture -geometry $normal_size $path_norm");
$ok2 = shell_exec($path_imagemagick."convert -size $max_width
$path_picture -geometry $thumbnail_size $path_thumb");
$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;
?>