Reputation: 51
want to delete a procuct and delete the image of the product but don't no what is missing. The product are deleting fine but don't delete the image
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";
}
}
Upvotes: 1
Views: 342
Reputation: 3250
try this
$file = "images/".$_FILES["imagem"]["name"];
unlink($file);
Upvotes: 0
Reputation: 19975
Check the unlink docs.
The unlink
requires the parameter to be a path to the file on your local filesystem.
From the looks of $frontpage_url
you are giving it an url to the image which is not supported by unlink
and also makes no sense on why that should work.
Example:
unlink('/home/path/to/image.jpg');
Upvotes: 2
Reputation: 4996
Try this:
unlink("images/".$_FILES["imagem"]["name"]);
If still not working, append your full path to the "images/" folder. E.g.:
unlink("public/uploads/images/".$_FILES["imagem"]["name"]);
Upvotes: 0