Delete image file in PHP
Delete image file: This tutorial will help you to delete image file from storage folder of your project or website using PHP programming language.
You can delete image, which you want to remove from your storage folder using unlink() function. That’s like:
<?php unlink('uploads/'.$row['image_file']); ?>
If you are want to delete image from database. So you need to select image value form database using where clause. You need to pass a unique value that’s like ID value and delete all records from database matching ID value with image from destination folder.
If you are set unlink() function in the page. You put the image value with the image path in the unlink function. Now your selected image is permanently delete from Folder.
Delete Image Permanently From Mysql Database and Directory in PHP:
<?php $id=$_GET["id"]; $qry=mysqli_query($mysqli,"SELECT `image_file` FROM `Table Name` WHERE `id`='$id'"); $row=mysqli_fetch_assoc($qry); unlink('uploads/'.$row['image_file']); $delete_qry=mysqli_query($mysqli,"DELETE FROM `Table Name` where `id`=$id"); ?>
Related posts