Hello friends, this is ours continuation post of previous how to upload and view files, now In this tutorial we will see that how to completely delete(remove) uploaded files from folder as well as from MySQL database table using PHP, you can delete any files pdf, mp3, image, video etc. when you upload any file it moves on particular folder and it's necessary to update or delete files from folder as well when you delete data from mysql. so let's have a look at this simple yet useful tutorial.
Read Also : Upload Insert, Update & Delete operations with Image [PDO Query]
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.
example :
Sample Code :
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.
Read Also : Upload Insert, Update & Delete operations with Image [PDO Query]
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.
example :
unlink("folder_name/".file_name);
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.
very nice post
ReplyDeletethanx...
good script
ReplyDeletethank you for sharing..
Thanks for sharing, codes work for me
ReplyDeleteunlink("uploads/".$row['file']); how to delete file from the folder
ReplyDeleteunlink("uploads/".$row['file']); how to delete file from the particular folder
ReplyDeletegive the particular folder name in "unlink()" function to delete files...
DeleteSir how I store music file in server folder and show in web page for user download.
ReplyDeletefile downloading is another part, i will post a tutorial for file download soon...
DeleteThanks sir .This code help me ..
ReplyDeleteThanks sir ... it help me.
ReplyDeleteMySQL is deprecated though, can you make on in MySQLi or PDO please?
ReplyDeletenice post....
ReplyDeletethis script is not download ???
ReplyDeleteI can't download script :(
ReplyDeleteThe download does not work!
ReplyDeleteHi ,
ReplyDeletei want to insert data in database when image file choose else not
so what we have to try there
hi,
ReplyDeletei want to insert image path in data base is image file selected else not
so, what i have to there ?
any one guide me please :)
Nice.. works like charm
ReplyDeleteHi.. Can you help me auto upload files to xampp using php?
ReplyDeleteDownload screwed!
ReplyDeleteplease help me
ReplyDelete