Here are the two scripts that upload and process the pictures and comments
upload00.php
<html>
<head>
<title>listing 9.13 A simple file upload form</title>
</head>
<body>
<form action="upload01.php" enctype="multipart/form-data" method="post" target="imain">
<input type='hidden' name='MAX_FILE_SIZE" value='204800'>
<p><strong>File to Upload: </strong> <input type="file" name="fileupload"></p>
Enter a comment about this picture: <textarea name="comments" rows="3" cols="40"></textarea>
<p><input type='submit' value="upload!"></p>
</form>
</body>
</html>
the processing script
upload01.php
<html>
<head>
<title>Our Family Gallery file upload script</title>
<?PHP
include ('text.css');
?>
</head>
</head>
<body>
<?php
$file_dir = "/home/litebear/public_html/effie/gallery/pics";
foreach($_FILES as $file_name => $file_array) {
$var1 = $file_array['tmp_name'];
$var2 = $file_array['name'];
$var3 = $file_dir . "/" . $file_array[name];
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'],
"$file_dir/$file_array[name]") or die ("could not copy");
}
}
$comments = trim($_POST['comments']);
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$percent_diff = $new_w/$origw;
$new_h = $origh * $percent_diff;
#################################
#
# start adding new code here
#
#################################
$job = 3;
if ($origw > $origh) {
$job = 1;
}
if ($origw < $origh) {
$job = 2;
}
SWITCH ($job) {
case 1:
$new_w = 100;
$new_h = $origh * (100/$origw);
break;
case 2:
$new_h = 100;
$new_w = $origw * (100/$origh);
break;
case 3:
$new_w = 100;
$new_h = 100;
break;
}
#################################
#
# end adding new code here
#
#################################
$dst_img = imagecreate($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path/$image_name",85);
return true;
}
$what_width = 100;
$file_dir2 = "/home/litebear/public_html/effie/gallery/thumbs";
thumbnail($file_dir,$file_dir2,$var2,$what_width);
?>
<?PHP
// date calculation
$ts = time(); //gets current server date as a timestamp
$tsgmt = gmmktime(); //gets timestamp for GMT
// date dst starts in the US
$start_dst = "20040404";
// date dst ends in the US
$end_dst = "20041031";
// set local offset from gmt
$est_off_set = 18000; // offset for Eastern Standard Time
// set local timestamps
$ts_est = $tsgmt - $est_off_set;
// adjust time stamps for DST
$est_date = date("Ymd", $ts_est);
if ($est_date >= $start_dst && $est_date <= $end_dst) { $ts_est = $ts_est + 3600; }
// end date calc
$fullpic = $var2;
$thumbpic = $var2;
$uploaddate = $est_date;
include ('db.php');
$sql = "INSERT INTO our_fam_gallery (comments, fullpic, thumbpic, uploaddate) VALUES ('$comments', '$fullpic', '$thumbpic', '$uploaddate')";
$result = mysql_query($sql);
?>
Your picture <B><I> <? echo $var2; ?></b></i> has been uploaded <br>and a thumbnail created.<br>
<IMG SRC = "<?PHP echo "./thumbs/" . $thumbpic; ?>"><br>
the comments were: <br>
<B><?PHP echo $comments; ?></b><br><br>
The load date is: <B><?PHP echo $uploaddate; ?></b><br><br>
You may upload another picture by clicking the <b>Add</b> button below, <br>
or peruse the gallery by clicking the <B>View</b> button, <br>
or you may choose any of the menu items from your left.
</body>
</html>
Hope this helps
Lite...