I’m trying to use the Unlink() statement to delete a image and info from my DB and folder, but it doesn’t delete the right image. It deletes the info correctly just not the image from the folder.
<!-- my link to delete -->
<a href="delete.php?cmd=delete&bId=<?=$bId?>">
<!-- DELETE DATA -->
<?
if($_GET["cmd"]=="delete"){
$bId = $_GET["bId"];
$file = "../images/brochures/$image";
$fh = fopen($file, 'w') or die("can't open file");
fclose($fh);
$path = "../images/brochures/";
$img_file = "$image";
$file = "$path"."$image";
if (!unlink($file)){
echo ("<span class='link'>Error Deleting: $img_file</span><br>");
}else{
echo ("<span class='link'>Deleted: $img_file</span><br>");
}
$sql = "DELETE FROM brochures WHERE bId=$bId";
$result = mysql_query($sql);
echo "<br><span class='link'>Information Deleted.</span><br>
<span class='link'>Go to <a href='admin_home.php' target='_parent'>Admin Home</a></span><br>";
}
?>