Reputation: 47
I try to delete image in my images directory but still not happen with my image file. I try to use with this code:
<a href=\"../admin/core/de_products.php?id=$row[id]\">Delete</a>
with this function:
<?php
require_once("../inc/con_db.php");
if(isset($_GET["id"]) && $_GET["id"]!="")
{
$image=mysql_query("SELECT * FROM products WHERE id='".$_GET["id"]."'") or die(mysql_error());`
if(mysql_num_rows($image)>0)
{
$row=mysql_fetch_array($image);
$image_name=$row["img_thumb"];`
$check=mysql_query("DELETE FROM products WHERE id='".$_GET["id"]."'") or die(mysql_error());
if($check)
{
@unlink("images/products/thumbs/".$image_name);
echo "Database has been deleted!";
}
else
{
echo "Oops, there is some problem";
}
}
}
?>
Upvotes: 0
Views: 206
Reputation: 2743
Are you getting any warnings or errors on the page or in your server logs? I suggest you remove the @ from in front of unlink until you have finished debugging this problem so that you can actually see the warnings it is likely throwing.
You might try checking that the .../thumbs/ directory is writable by whatever user your server is running as. Or, you can just set its permissions to 777 if you're lazy like me. To delete a file, you need write permissions on the directory in which it resides.
Upvotes: 1