Menghapus / Delete file dengan PHP menggunakan fungsi UNLINK

Bagaimana kita dapat menghapus file dengan menggunakan bahasa pemrograman PHP? PHP telah menyediakan sebuah fungsi untuk penghapusan FILE. sayangnya saya tidak mempergunakan sebelum-sebelumnya dikarenakan sebuah keinginan untuk historical data. Namun sebaiknya file file yang datanya di dalam database terhapus sebaiknya ikut kita hapus, karena bakal memenuhkan ruang penyimpanan saja.

Berikut ini adalah cara sederhana untuk Menghapus / Delete file dengan PHP menggunakan fungsi unlink()

Kronologi :

  1. Menghapus data di database (Salah satu field data di database tersebut menyimpan nama file yang akan dihapus).
  2. File ikut terhapus dengan menyertakan fungsi unlink() di dalam syntax PHP.
  3. Data dan File Terhapus, menghemat beban database dan Disk Space.
  4. Selesai
Di dalam Program



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

Komentar FB


Probably Related Article



23 comments:

John said...
August 21, 2010 at 11:05 AM

usefull post

ezz said...
August 24, 2010 at 4:22 AM

very interesting script, can really help uludshenii site structure.

sql said...
August 24, 2010 at 10:07 AM

Great post, I like the script

KVM Switches said...
June 6, 2011 at 10:12 PM

Good post and interesting script..! I must appreciate this post For more information! I will be in touch. Thanks!

Seo Melbourne said...
June 8, 2011 at 2:45 AM

I wished to thank you for this nice read!! I really like your viewpoint on this theme. Congratulations to the writer of the blog!

afrodisiacos sex shop said...
October 1, 2011 at 11:28 AM

In my view one and all should browse on this.

Pak Tani said...
January 29, 2012 at 10:58 PM

mantap scriptnya, makasih panduannya

Jersey Daily Deals said...
March 21, 2012 at 8:25 PM

This site is create by PHP comment.This comment is not so easy and too hard to understand.I am waiting for another easy comment in this site in the future.

Port Dickson Resort said...
April 8, 2012 at 5:06 AM

This site is PHP language related.It is easy than other language.

mirrored bedroom furniture said...
August 5, 2012 at 3:57 AM

Hey
The articles is truly excellent:, I think that is among the most vital info for me, You are wonderful! Thank you!

coupons said...
August 15, 2012 at 5:58 AM

Hi
Great article once again! Thumbs up! I believe people should acquire a lot from this website its really user pleasant.
With Best Wishes
printable coupons | coupon code | promo code | online coupons | coupons | coupon

kuceng21 said...
December 19, 2012 at 1:03 AM

Terimakasih mastah, langsung ane praktekin deh, :D

vio said...
April 13, 2013 at 12:10 AM

wauidihh mangtabs gan.. (y)
dr dlu pas hapus file cma yang di databse doang yg keapuss, baru nyadar kalo yg di filenya gak keapuss :hammer:

resolved with unlink();

mobil baru said...
December 23, 2013 at 10:25 PM

mantao gan, ini yang ane cari

prieku said...
April 25, 2014 at 6:31 AM

Mantabss....ini yang dicari2

fajar ardiyanto said...
September 14, 2014 at 11:01 PM

Ini dia yg d cari gan. Mkssihh

Company Registration Delhi said...
November 27, 2014 at 2:39 AM

That is an extremely smart written article. I will be sure to bookmark it and return to learn extra of your useful information. Thank you for the post. I will certainly return.

to.rizki@gmail.com said...
November 27, 2014 at 7:17 PM

GOBLOK!!!

to.rizki@gmail.com said...
November 27, 2014 at 7:18 PM

Blogger
Komentar Anda telah disimpan.
Mungkin membutuhkan waktu beberapa saat untuk komentar Anda tampil di situs.
18 Comments
Close this window Jump to comment form
1 – 18 of 18

Fans Neymar said...
January 19, 2015 at 9:05 AM

Nice BLog Salam Sukses Selalu
Wisata Dewasa
Pembesar Penis
Obat Kuat Pria
ObatPerangsang Sex Toys Pria
Pembesar Penis Permanen

Software Development Company in Gurgaon said...
September 30, 2015 at 3:11 AM

nice information. thanks.

Web Designers Pitampura said...
March 11, 2016 at 10:49 PM

Blogging is the new poetry. I find it wonderful and amazing in many ways.

Web Designers Pitampura said...
March 11, 2016 at 10:50 PM

I certainly agree to some points that you have discussed on this post. I appreciate that you have shared some reliable tips on this review.

Related Posts by Categories



Widget by