Hi, today i am going to tell you about how to remove the file or picture from folder and database using php, some developers they are not care to delete a picture or file while deleting a records from database they keep the files related to records and it will effects on server storage, we will find many solutions to remove files from folder i will give you a easy process let's see how we do this.
Live Demo
Download Script
PHP
here connect this file to database and retrieve the records from gallery table here i am just retrieving one record only if you want you can access all records and keep it in while loop, now i am just place the image tag and take the anchor tag for delete button and place the delete.php file in href and i just pass the gallery id to del variable<div id="box"> <?php $sql=mysql_query("select * from gallery limit 1"); $row=mysql_fetch_array($sql); ?> <img src="images/<?php echo $row['image']?>" /> <p></p> <a href="delete.php?del=<?php echo $row['galleryid']?>" class="link">Delete</a> </div>
delete.php
here connect this file to database, now retrieve the image from gallery table by using where query condition and assign the $del variable to galleryid, now use unlink() method to remove the files or pictures from folder unlink("images/$row[image]"); inside the function just give the folder path and file name to remove after the function write the query to delete the record<?php extract($_REQUEST); include('db.php'); $sql=mysql_query("select * from gallery where galleryid='$del'"); $row=mysql_fetch_array($sql); unlink("images/$row[image]"); mysql_query("delete from infogall where infoid='$del'"); header("Location:index.php"); ?>
khasim bai plz share the code of add and cancel friends request like facebook plz
ReplyDeleteGreat Article Image Processing Projects Deep Learning Projects for Final Year JavaScript Training in Chennai JavaScript Training in Chennai The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai
Deletegood post bro
ReplyDeletethanks from http://www.blogonmind.com
thanks broo
ReplyDeletevery helpfull for me :)
Where did you assign a value to variable 'del'?
ReplyDeleteI think you want it like this:
$del = intval($_GET['id']);
mehn u are a real genious ,worked perfectly, god bless INDIAN gurus like you
ReplyDeleteThank You so Much very easy code
ReplyDeletethank you
ReplyDeleteonly remove value from database but not delete file from folder. why.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteit's not working !!
ReplyDelete$i=$_REQUEST['did'];
ReplyDelete$q=mysqli_query($con,"SELECT PHOTO FROM tbl_student WHERE ID=$i");
$row=mysqli_fetch_array($q,MYSQLI_BOTH);
unlink("upload/".$row['PHOTO']); // Folder Path
mysqli_query($con,"delete from tbl_student where ID=$i");
header("location: http://localhost/php/operation/display.php");
good post boss
ReplyDeleteIts not working
ReplyDeleteNot working:(
ReplyDeleteOpen source as substantiated itself a help for these software engineers as assets could be used at the maximum with least cost. Top Expert Cakephp Developers
ReplyDeleteits no working only delete the data from database not file from directory
ReplyDeletePHP is significantly immaculate with driving working structures, web servers and various other differing stages.Why use Laravel
ReplyDeleteits no working only delete the data from database not file from directory
ReplyDeleteIt takes normally a few years for the application to get considered, despite the fact that patent workplaces do an incredibly messy activity of considering. https://www.apkmacpc.com/itools-crack/
ReplyDeletegood post bhai www.coincryptograph.com
ReplyDeleteyes this solution worked for me. thank you so much..thanks alotttttt
ReplyDeleteI truly get pleasure from while I read your blogs and its content.
ReplyDeletebest logo design companies in the world
Great thanks for sharing this article post. Really thank you! Keep writing.
ReplyDeleteupload file