Problemer med imagefilter function!
Er der en som kan finde ud af, hvad jeg gøre forkert?Link: http://www.designunltd.dk/phptest/chapter07/upload_image.htm
Fejl: http://www.designunltd.dk/phptest/chapter07/modifyimage.php
Fatal error: Call to undefined function: imagefilter() in /var/www/html/phptest/chapter07/modifyimage.php on line 31
Kode:
<html>
<head>
<title>Upload your pic to our site!</title>
</head>
<body>
<form name="form1" method="post" action="check_image.php"
enctype="multipart/form-data">
<table border="0" cellpadding="5">
<tr>
<td>Image Title or Caption<br>
<em>Example: You talkin' to me?</em></td>
<td><input name="image_caption" type="text" id="item_caption" size="55"
maxlength="255"></td>
</tr>
<tr>
<td>Your Username</td>
<td><input name="image_username" type="text" id="image_username" size="15"
maxlength="255"></td>
</tr>
<td>Upload Image:</td>
<td><input name="image_filename" type="file" id="image_filename"></td>
</tr>
</table>
<br>
<em>Acceptable image formats include: GIF, JPG/JPEG, and PNG.</em>
<p align="center"><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear Form">
</p>
</form>
</body>
</html>
-----
<?php
//connect to the database
$link = mysql_connect("xxxxx", "xxxxx", "xxxxx");
or die("Could not connect: " . mysql_error());
mysql_select_db("xxxxx", $link)
or die (mysql_error());
//make variables available
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_FILES['image_filename']['name'];
$today = date("Y-m-d");
//upload image and check for image type
$ImageDir ="../images/";
$ImageName = $ImageDir . $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
$ImageName)) {
chmod($ImageName, 0755);
//get info about the image being uploaded
list($width, $height, $type, $attr) = getimagesize($ImageName);
//**insert these new lines
if ($type > 3) {
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.";
} else {
//image is acceptable; ok to proceed
//**end of inserted lines
//insert info into image table
$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();
//change the following line:
$newfilename = $ImageDir . $lastpicid . ".jpg";
//**insert these lines
if ($type == 2) {
rename($ImageName, $newfilename);
} else {
if ($type == 1) {
$image_old = imagecreatefromgif($ImageName);
} elseif ($type == 3) {
$image_old = imagecreatefrompng($ImageName);
}
//"convert" the image to jpg
$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);
}
$url = "location: showimage.php?id=" . $lastpicid;
header($url);
//**end of inserted lines
}
}
?>
-----
<?php
//connect to the database
$link = mysql_connect("xxxxx", "xxxxx", "xxxxx")
or die("Could not connect: " . mysql_error());
mysql_select_db("xxxxx", $link)
or die (mysql_error());
//make variables available
$id = $_REQUEST['id'];
if (isset($_REQUEST['mode'])) {
$mode = $_REQUEST['mode'];
} else {
$mode = '';
}
//get info on the pic we want
$getpic = mysql_query("SELECT * FROM images WHERE image_id = '$id'")
or die(mysql_error());
$rows = mysql_fetch_array($getpic);
extract($rows);
$image_filename = "../images/" . $image_id . ".jpg";
list($width, $height, $type, $attr) = getimagesize($image_filename);
?>
<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="<?php echo $image_filename; ?>" align="left"
<?php echo $attr; ?> >
<strong><?php echo $image_caption; ?></strong><br>
It is <?php echo $width; ?> pixels wide a
nd <?php echo $height; ?> pixels high.<br>
It was uploaded on <?php echo $image_date; ?>
by <?php echo $image_username; ?>.
<?php
if ($mode == 'change') {
echo "<font color=\"CC0000\"><em><strong>Your image has been
modified.</strong></em></font>";
echo "<img src=\"" . $image_filename . "\" align=\"left\" " .
$attr . ">";
} else {
?>
<?php
//end the else
}
?>
<hr>
<p><em><strong>Modifying Your Image</strong></em></p>
<form action="modifyimage.php" method="post">
<p>
Please choose if you would like to modify your image with any of
the following options. If you would like to preview the image
before saving, you will need to hit your browser's 'back' button
to return to this page. Saving an image with any of the
modifications listed below <em>cannot be undone.</em>
</p>
<input name="id" type="hidden" value="<?php echo $image_id; ?>">
<input name="bw" type="checkbox">black & white<br>
<p align="center">
<input type="submit" name="action" value="preview">
<input type="submit" name="action" value="save">
</p>
</form>
</body>
</html>
-----
<?php
//connect to the database
$link = mysql_connect("xxxxx", "xxxxx", "xxxxx")
or die("Could not connect: " . mysql_error());
mysql_select_db("xxxxx", $link)
or die (mysql_error());
//make variables available
$id = $_POST['id'];
if (isset($_POST['bw'])) {
$bw = $_POST['bw'];
} else {
$bw = '';
}
$action = $_POST['action'];
//get info on the pic we want
$getpic = mysql_query("SELECT * FROM images WHERE image_id = '$id'")
or die(mysql_error());
$rows = mysql_fetch_array($getpic);
extract($rows);
$image_filename = "../images/" . $image_id . ".jpg";
list($width, $height, $type, $attr) = getimagesize($image_filename);
$image = imagecreatefromjpeg("$image_filename");
if ($bw == 'on') {
imagefilter($image, IMG_FILTER_GRAYSCALE);
}
if ($action == "preview") {
header("Content-type:image/jpeg");
imagejpeg($image);
}
if ($action == "save") {
imagejpeg($image, $image_filename);
$url = "location:showimage.php?id=". $id . "&mode=change";
header($url);
}
?>
