topical media & game development
basic-php-07-check-image-rev03.php / php
<?php
//connect to the database
link)
or die (mysql_error());
//make variables available
_POST['image_caption'];
_POST['image_username'];
_FILES['image_filename']['name'];
ImageDir ="c:/Program Files/Apache Group/Apache2/test/images/";
//**INSERT THIS LINE:
ImageDir . "thumbs/";
//**END OF INSERT
ImageDir . _FILES['image_filename']['tmp_name'],
width, type, ImageName);
//**delete these lines
switch (ext = ".gif";
break;
case 2:
ext = ".png";
break;
default:
echo "Sorry, but the file you uploaded was not a GIF, JPG, or " .
"PNG file.<br>";
echo "Please hit your browser's 'back' button and try again.";
}
//**end of deleted lines
//**insert these new lines
if (insert = "INSERT INTO images
(image_caption, image_username, image_date)
VALUES
('image_username', 'insertresults = mysql_query(lastpicid = mysql_insert_id();
//change the following line:
ImageDir . type == 2) {
rename(newfilename);
} else {
if (image_old = imagecreatefromgif(type == 3) {
ImageName);
}
//"convert" the image to jpg
width, image_jpg, width, width, image_jpg, image_old);
imagedestroy(newthumbname = lastpicid . ".jpg";
//get the dimensions for the thumbnail
width * 0.10;
height * 0.10;
//create the thumbnail
newfilename);
thumb_width, thumb, thumb_width, width, thumb, largeimage);
imagedestroy(url = "location: showimage.php?id=" . url);
//**end of inserted lines
}
?>
<!-- DELETE THESE LINES
<html>
<head>
<title>Here is your pic!</title>
</head>
<body>
<h1>So how does it feel to be famous?</h1><br><br>
<p>Here is the picture you just uploaded to our servers:</p>
<img src="images/<?php echo ext; ?>" align="left">
<strong><?php echo ext; ?> image.<br>
It is <?php echo height; ?> pixels high.<br>
It was uploaded on <?php echo
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.