Jay
Jay

Reputation: 51

Php unlink() dont delete a image file

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

Answers (3)

Muhammad
Muhammad

Reputation: 3250

try this

$file = "images/".$_FILES["imagem"]["name"];
unlink($file);

Upvotes: 0

majidarif
majidarif

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

mirelon
mirelon

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

Related Questions