90 likes | 420 Views
File. Bayu Priyambadha, S.Kom. File (1). PHP provide some functions to manage file, likes : Open / Close Write / Read Add / append Fopen = for open file Fget = for get entire file. File (2). Try This!!. <? $file = “contoh.txt”; $fp = fopen($file, “r”); while (!feof($fp)) {
E N D
File Bayu Priyambadha, S.Kom
File (1) • PHP provide some functions to manage file, likes : • Open / Close • Write / Read • Add / append • Fopen = for open file • Fget = for get entire file
Try This!! <? $file = “contoh.txt”; $fp = fopen($file, “r”); while (!feof($fp)) { $baris = fgets($fp, 1024); echo $baris.”<br />”; } fclose($fp); ?>
Try This!! <? $file = “contoh.txt”; $fp = fopen($file, “r”); while (!feof($fp)) { $baris = fread($fp, 30); echo $baris; } fclose($fp); ?>
Try this!! <? $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); ?>
Upload file • Use enctype="multipart/form-data" on html form • Use <input> 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
TRY THIS!! <?php $user_file = $_FILES[“file_user”][“tmp_name”]; $filename = $_FILES[“file_user”][“name”]; $tujuan = “”; copy($user_file, $tujuan.$filename); ?>