Jump to content

unlink() function not deleting files


joaomagico

Recommended Posts

I have a <a>, on click delete a product from database that is on server, I want to delete the product 
and the same time delete the image of that product. I using unlink() my code delete the product but don't 
delete the image and I don't no why someone can tell me what is missing ? 
 
if((isset($_GET["remove"])) && ($_GET["remove"] != "")){

$idproduct = $_GET["remove"];

$sql ="DELETE FROM product WHERE idproduct = '".$idproduct."'";
if(mysqli_query($connect, $sql) or die ("Erro")){

//the part that don't work
$file = $frontpage_url."/images/".$_FILES["imagem"]["name"]; unlink($file);

echo "success";

}
}
Link to comment
Share on other sites

that might be where your images are stored, but you must specify which image you want to delete, which is why i asked what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder?

 

if you have no relationship that tells you which image belongs with which row in the product table, how do you expect to be able to delete the proper image file?

Link to comment
Share on other sites

that might be where your images are stored, but you must specify which image you want to delete, which is why i asked what method have you used to associate the row in the product database table with the image that was stored in the $frontpage_url."/images/" folder?

 

if you have no relationship that tells you which image belongs with which row in the product table, how do you expect to be able to delete the proper image file?

 

Yes that is my problem how I associate the image with the row I want to delete ? 

Link to comment
Share on other sites

It's a little late now.  If the database doesn't have the image name saved with the product, and if the image name is not simply product id, no amount of programming is going to join them for you.  You have to develop a scheme to connect the two before you can continue with this project. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.