Berikut ini adalah cara sederhana untuk Menghapus / Delete file dengan PHP menggunakan fungsi unlink()
Kronologi :
- Menghapus data di database (Salah satu field data di database tersebut menyimpan nama file yang akan dihapus).
- File ikut terhapus dengan menyertakan fungsi unlink() di dalam syntax PHP.
- Data dan File Terhapus, menghemat beban database dan Disk Space.
- Selesai
if($_GET[action]=="delete"){
// dapatkan nama file
$sql_="select id_video, judul, file
from tb_video where id_video=$_GET[id]";
$hasil_=mysqli_query($link,$sql_);
$data_=mysqli_fetch_array($hasil_);
//delete row
$sql = "delete from tb_video where id_video=$_GET[id]";
$hasil = mysqli_query($link,$sql);
//delete file
if($hasil_) {
unlink("../source/$data_[file]");
}
//reload page otomatis dengan javascript
echo "<script language=javascript>
alert('Data Berhasil Dihapus');</script>";
echo '<script type=text/javascript>
<!--
window.location = "index.php"
//-->
</script>';
}
Demikian sebuah contoh sederhana untuk Menghapus / Delete file dengan PHP menggunakan fungsi UNLINK. Semoga membantu



7 comments:
usefull post
very interesting script, can really help uludshenii site structure.
Great post, I like the script
Good post and interesting script..! I must appreciate this post For more information! I will be in touch. Thanks!
I wished to thank you for this nice read!! I really like your viewpoint on this theme. Congratulations to the writer of the blog!
In my view one and all should browse on this.
mantap scriptnya, makasih panduannya
Post a Comment