ISENG BLOGER

Membuat, Membuka, Membaca, Menulis, Menutup, and Menghapus file dengan PHP



Bismillah
Langsung aja gan…. mungkin catatan ini bisa membantu anda. Berikut ini adalah cara2 untuk Membuat, Membuka, Membaca, Menulis, Menutup, and Menghapus file dengan PHP…

Membuat file

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);

Membuat File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file

Membuka File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //open file for writing ('w','r','a')...

Membaca File

$my_file = 'file.txt';
$handle = fopen($my_file, 'r');
$data = fread($handle,filesize($my_file));

Menulis File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);

Menambahkan string ke dalam File

$my_file = 'file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
$data = 'New data line 1';
fwrite($handle, $data);
$new_data = "\n".'New data line 2';
fwrite($handle, $new_data);

Menutup File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
//write some data here
fclose($handle);

Menghapus File

$my_file = 'file.txt';
unlink($my_file);


Responses

0 Respones to "Membuat, Membuka, Membaca, Menulis, Menutup, and Menghapus file dengan PHP"

Posting Komentar

 

Categories

Recent Comments

Popular Posts

Return to top of page Copyright © 2012 | Iseng Bloger Converted into Blogger Template by Riyan Apri