I cant delete an uploaded image by unlink function
Posted: Mon Nov 17, 2008 10:14 pm
when i upload a new image, I want the old image been deleted. I tried to use unlink, but it just not working. here is my code, can anyone tell me whats wrong with it? $imagedata is the file name passed from the previous page.
Code: Select all
<?php
require_once('db.php');
$address = $_POST[address];
$imagedata = $_POST[imagedata];
$path="upload/$imagedata";
$image1 = $_FILES['image1']['name'];
$new_name1 = "upload/" . md5(uniqid(rand(), true)) . substr($image1, strrpos($image1, "."));
move_uploaded_file($_FILES['image1']['tmp_name'], $new_name1);
$filesize1=$_FILES['image1']['size'];
if($filesize1!= 0)
{
$image1 = basename($new_name1);
$query = mysql_query("UPDATE image SET imagedata='$image1' where address='$address' && thumb='1'");
unlink($path);
echo "image has been changed, you will be redirecting to previous page in 3 seconds";
}
?>