Kawan pernah mengupload data dalam database kemudian menyimpan file kedalam folder?????? Nah bagaimana kalau ingin menghapus data itu???? YA….pakai UNLINK . Tujuanya adalah menghapus data didalam database dan data dalam folder yang telah kita tentukan. Misalkan saya punya Tabel : Product Field : id, code,name,fileTipe Langsung saja kawan, ini script Unlink di php: <!--? php include "../config.php"; // membaca id file yang akan dihapus $id = $_GET['id']; $code=$_GET['code']; // membaca nama file yang akan dihapus berdasarkan id $query = "SELECT * FROM product WHERE code='$code' and id = '$id'"; $hasil = mysql_query($query); $data = mysql_fetch_array($hasil); $namaFile = $data['name']; // query untuk menghapus informasi file berdasarkan id $query = "DELETE FROM product where id = $id"; mysql_query($query); // menghapus file dalam folder sesuai namanya unlink('NamaFolderAnda/'.$namaFile); echo "File telah dihapus"; ?--> Ok….Jadi kawan…Selamat
Mencoba.. <Lengkap PHP Filesystem Referensi Definisi dan PenggunaanThe unlink() fungsi menghapus file. Fungsi ini mengembalikan TRUE pada keberhasilan, atau FALSE pada kegagalan. Sintaksis
Contoh<?php <Lengkap PHP Filesystem Referensi (PHP 4, PHP 5, PHP 7, PHP 8) unlink — Deletes a file Descriptionunlink(string
Parametersfilename Path to the file. If the file is a symlink, the symlink will be deleted. On Windows, to delete a symlink to a directory, rmdir() has to be used instead. context A context stream resource. Return Values Returns Changelog
ExamplesExample #1 Basic unlink() usage
See Also
anagai at yahoo dot com ¶ 10 years ago
dexen dot devries at gmail dot com ¶ 11 years ago
deen804 at gmail dot com ¶ 8 years ago
federico at poisonfx dot com ¶ 11 years ago
chris at vibenewmedia dot com ¶ 18 years ago
PD ¶ 14 years ago
gotdalife at gmail dot com ¶ 14 years ago
Eric ¶ 8 years ago
llmll at gmx dot de ¶ 7 years ago
divinity76+spam at gmail dot com ¶ 1 month ago
Keatran ¶ 2 years ago
Alex, the Marrch Ca'at ¶ 9 years ago
|