I did the watermark images tutorial and it is working good. I implement the watermark function in an upload image tutorial, chanced a little bit, checked if it is still working and no, it isn't working any more and I can't get it let working again.
Can anybody tell me why it is not working?
This is the upload image page;
<?php include 'init.php'; if (!logged_in()) { header('Location: administratie.php'); exit(); } include 'template/header.php'; ?> <h3>Upload foto</h3> <?php if (isset($_FILES['image'], $_POST['album_id'])) { $image_name = $_FILES['image'] ['name']; $image_size = $_FILES['image'] ['size']; $image_temp = $_FILES['image'] ['tmp_name']; $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $image_ext = strtolower(end(explode('.',$image_name))); $album_id = $_POST['album_id']; $errors = array(); if (empty($image_name) || empty($album_id)) { $errors[] = 'Niet alles is ingevuld'; } else { if (in_array($image_ext, $allowed_ext) === false) { $errors[] = 'Bestandsnaam is niet toegestaan.'; } if ($image_size > 2097152) { $errors[] = 'Je kan maximaal 2mb uploaden.'; } if (album_check($album_id) === false) { $errors[] = 'Er kan niet naar dit album worden geupload.'; } } if (!empty($errors)) { foreach ($errors as $error) { echo $error, '<br />'; } } else { upload_image($image_temp, $image_ext, $album_id); header('Location: view_album.php?album_id='.$album_id); exit(); } //This is the watermark_image part $image_output = 'uploads/' . md5(microtime(true)).'.png'; watermark_image($image_temp, $image_output); } $albums = get_albums(); if (empty($albums)) { echo '<p>Je hebt nog geen albums. <a href="create_album.php">Maak een album.</a></p>'; } else { ?> <form action="" method="post" enctype="multipart/form-data"> <p>Kies een foto:<br /><input type="file" name="image" /></p> <p> Kies een album:<br /> <select name="album_id"> <?php foreach ($albums as $album) { echo '<option value="', $album['id'], '">', $album['name'], '</option>'; } ?> </select> </p> <p><input type="submit" value="Upload" /></p> </form> <?php } include 'template/footer.php'; ?>The function is;
<?php function upload_image($image_temp, $image_ext, $album_id) { $album_id = (int)$album_id; mysql_query("INSERT INTO `images` VALUES ('', '".$_SESSION['user_id']."', '$album_id', UNIX_TIMESTAMP(), '$image_ext')"); $image_id = mysql_insert_id(); $image_file = $image_id.'.'.$image_ext; move_uploaded_file($image_temp, 'uploads/'.$album_id.'/'.$image_file); create_thumb('uploads/'.$album_id.'/', $image_file, 'uploads/thumbs/'.$album_id.'/'); } function get_images($album_id) { $album_id = (int)$album_id; $images = array(); $image_query = mysql_query("SELECT `image_id`, `album_id`, `timestamp`, `ext` FROM `images` WHERE `album_id`=$album_id AND `user_id`=".$_SESSION['user_id']); while ($images_row = mysql_fetch_assoc($image_query)) { $images[] = array( 'id' => $images_row['image_id'], 'album' => $images_row['album_id'], 'timestamp' => $images_row['timestamp'], 'ext' => $images_row['ext'] ); } return $images; } function image_check($image_id) { $image_id = (int)$image_id; $query = mysql_query("SELECT COUNT(`image_id`) FROM `images` WHERE `image_id`=$image_id AND `user_id`=".$_SESSION['user_id']); return (mysql_result($query, 0) == 0) ? false : true; } //The watermark_image part function watermark_image($image, $output) { $info = getimagesize($image); switch ($info['mime']){ case 'image/jpeg'; $main = imagecreatefromjpeg($image); break; case 'image/png'; $main = imagecreatefrompng($image); break; case 'image/gif'; $main = imagecreatefromgif($image); break; default: return false; } imagealphablending($main, true); $overlay = imagecreatefrompng('watermark.png'); imagecopy($main, $overlay, 5, 5, 0, 0, imagesx($overlay), imagesy($overlay)); imagepng($main, $output); } function delete_image($image_id) { $image_id = (int)$image_id; $image_query = mysql_query("SELECT `album_id`, `ext` FROM `images` WHERE `image_id`=$image_id AND `user_id`=".$_SESSION['user_id']); $image_result = mysql_fetch_assoc($image_query); $album_id = $image_result['album_id']; $image_ext = $image_result['ext']; unlink('uploads/'.$album_id.'/'.$image_id.'.'.$image_ext); unlink('uploads/thumbs/'.$album_id.'/'.$image_id.'.'.$image_ext); mysql_query("DELETE FROM `images` WHERE `image_id`=$image_id AND `user_id`=".$_SESSION['user_id']); } ?>Thanks in advance.