I have created this script which i got from a book. I'm looking to upload images and resize them. for some reason i can't get this work i've checked the code a number of time but cant work it out. Thanks
<?php
$link = mysql_connect("localhost", "name", "password")
or die("could not connect:" . mysql_error());
mysql_select_db("testme", $link)
or die (mysql_error());
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_FILES['image_filename']['name'];
$today = date("y-m-d");
$imagedir = "productimages/";
$imagethumb = $imagedir . "thumbimage/";
$imagename = $imagedir . $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $imagename)) {
list($width,$height,$type,$attr) = getimagesize($imagename);
if ($type > 3){
echo "Sorry but the file could not be uploaded nor jpg or " . "png file.<br>";
echo "Please hit your return button.";
} else {
$insert = "INSERT INTO images(image_caption, image_username, image_date) VALUES ('$image_caption','$image_username','$today')";
$insertresults = mysql_query($insert)
or die(mysql_error());
$lastpicid = mysql_insert_id();
$newfilename = $imagedir . $lastpicid . ".jpg";
if ($type == 2){
rename($imagename, $newfilename);
} else {
if ($type == 1){
$image_old = imagecreatefromgif($imagename);
}elseif ($type == 3) {
$image_old = imagecreatefrompng($imagename);
$image_jpg = imagecreatetruecolor($width, $height);
imagecopyresampled($image_jpg, $image_old, 0,0,0,0, $width, $height, $width, $height);
imagejpeg($image_jpg, $newfilename);
imagedestroy($image_old);
imagedestroy($image_jpg);
}
$newthumbname = $imagethumb . $lastpicid . ".jpg";
$thumb_width = $width * 0.10;
$thumb_height = $height * 0.10;
$largeimage = imagecreatefromjpeg($newfilename);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $largeimage, 0,0,0,0, $thumb_width, $thumb_height, $width, $height);
imagejpeg($thumb, $newthumbname);
imagedestroy($largeimage);
imagedestroy($thumb);
$url = "location: imagepage.php?id=" . $lastpicid;
header ($url);
}
}
?>