Here i am going to use the same old Database and table with dumping data which have been used in ours file uploading tutorial.
In PHP using unlink() function we can delete files from folder.
Sample Code :
$res=mysql_query("SELECT file FROM tbl_uploads WHERE id=".$_GET['remove_id']); $row=mysql_fetch_array($res); mysql_query("DELETE FROM tbl_uploads WHERE id=".$_GET['remove_id']); unlink("uploads/".$row['file']);
Script explained :
– First write select query to fetch file from database.
– This code can be work with if(isset($_GET) condition.
– After fetching file put the fetched file into the unlink() function like above.
That’s it guys, hope you like this short and simple tutorial.