When I try to add your code to the end of the upload script i use,i get this error:
"
Parse error: syntax error, unexpected T_IF in /images/imageupload.php on line 30"
here's the script:
<?php
$path = "/images/";
$max_size = 100000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "File is too big."; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/bmp") || ($HTTP_POST_FILES['userfile']['type']=="image/tiff")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "Change filename.<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "Transfer failed!<br>\n"; exit; } else { echo ""; }
} else { echo "Wrong filetype<br>\n"; exit; }
}
chmod($path.$HTTP_POST_FILES['userfile']['name'],0777)
///////BEGIN THUMB CODE///////
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($_FILES['image']['tmp_name']);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($_FILES['image']['tmp_name']);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
$img = @imagecreatefromgif($_FILES['image']['tmp_name']);
}
$thumb_path = "/images/$image";
$size=60;
//echo "Width is $width and height is $height<br>";
# If the image is larger than the max shrink it
$width = imagesx($img);
$height = imagesy($img);
if ($width<=$height)
{
$new_height=$size;
$new_width=$size;
//$new_width = ($new_height/$height)*$width;
}
else
{
$new_width=$size;
$new_height=$size;
//$new_height = ($new_width/$width)*$height;
}
$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);
imagedestroy($img);
$img = $tmp_img;
if ($ext == 'jpg' || $ext == 'jpeg') {
imagejpeg($img, $thumb_path);
} else if ($ext == 'png') {
imagepng($img, $thumb_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
imagegif($img, $thumb_path);
}
/////////END THUMB CODE///////////
?>