Modifying a image is very similar to the form to add the image except for the image thumbnail. Clicking on the thumbnail will call the javascript function viewLargeImage() which will open a popup displaying the full-sized image. If you checkout the form code you can see that we use htmlspecialchars() function when printing the image description in the textarea.
After you click the "Modify Image" button we continue saving the new information and also save the new image ( if a new one is provided ). The process is just a repetition of the code to modify album data and image. The difference is that now we modify two images, the full-sized image and the thumbnail.
Code:
<!-- google_ad_section_start(weight=ignore) -->
// ... some code here
if (isset($_POST['txtTitle'])) {
$albumId = $_POST['cboAlbum'];
$imgTitle = $_POST['txtTitle'];
$imgDesc = $_POST['mtxDesc'];
if ($_FILES['fleImage']['tmp_name'] != '') {
$images = uploadImage('fleImage', GALLERY_IMG_DIR);
if ($images['image'] == '' && $images['thumbnail'] == '') {
echo "Error uploading file";
exit;
}
$image = "'" . $images['image'] . "'";
$thumbnail = "'" . $images['thumbnail'] . "'";
$sql = "SELECT im_image, im_thumbnail
FROM tbl_image
WHERE im_id = $imgId";
$result = mysql_query($sql)
or die('Error, get image info failed. ' .
mysql_error());
$row = mysql_fetch_assoc($result);
unlink(GALLERY_IMG_DIR . $row['im_image']);
unlink(GALLERY_IMG_DIR . 'thumbnail/' . $row['im_thumbnail']);
} else {
// the old image is not replaced
$image = "im_image";
$thumbnail = "im_thumbnail";
}
if (!get_magic_quotes_gpc()) {
$albumName = addslashes($albumName);
$albumDesc = addslashes($albumDesc);
}
$sql = "UPDATE tbl_image
SET im_album_id = $albumId,
im_title = '$imgTitle',
im_description = '$imgDesc',
im_image = $image,
im_thumbnail = $thumbnail,
im_date = NOW()
WHERE im_id = $imgId";
mysql_query($sql) or die('Error, update image failed : ' .
mysql_error());
echo "<script>window.location.href = 'index.php?page=image-detail&imgId=$imgId';</script>";
}
// ... more code here
<!-- google_ad_section_end -->
Bookmarks