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
https://forums.phpfreaks.com/topic/286987-unlink-function-not-deleting-files/
Share on other sites

the $_FILES array is the information about the file when the file was uploaded. the $_FILES array doesn't exist after that point. 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?

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?

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 ? 

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.