Bayu Priyambadha, S.Kom
PHP provide some functions to manage file, likes : Open / Close Write / Read Add / append Fopen = for open file Fget = for get entire file
ModeKeterangan r Membuka file untuk proses pembacaan (reading) r+ Membuka file untuk proses pembacaan (reading) dan penulisan w Membuka file untuk proses penulisan (writing) w+ Membuka file untuk proses penulisan dan pembacaan. a Membuka file untuk proses penambahan data (appending) a+Membuka file untuk proses pembacaan dan penambahan data.
<? $file = “contoh.txt”; $fp = fopen($file, “r”); while (!feof($fp)) { $baris = fgets($fp, 1024); echo $baris.” ”; } fclose($fp); ?>
<? $file = “contoh.txt”; $fp = fopen($file, “r”); while (!feof($fp)) { $baris = fread($fp, 30); echo $baris; } fclose($fp); ?>
<? $file = “contoh.txt”; $fp = fopen($file, “w”); fwrite($fp, “Menuliskan ke dalam file”); fclose($fp); $fp = fopen($file, “a”); fputs($fp, “Menambahkan ke dalam file”); fclose($fp); $fp = fopen($file, “r”); while (!feof($fp)) { $baris = fgets($fp, 1024); echo $baris; } fclose($fp); ?>
Use enctype="multipart/form-data" on html form Use with type=“file” $_FILES[field name][atribut] to get file Atribute : tmp_name = temporary path where the file will be placed name = file name move_uploaded_file() or copy() for move file from temporary path to real destination
<?php $user_file = $_FILES[“file_user”][“tmp_name”]; $filename = $_FILES[“file_user”][“name”]; $tujuan = “”; copy($user_file, $tujuan.$filename); ?>