-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path14_file_handling.php
More file actions
30 lines (26 loc) · 827 Bytes
/
14_file_handling.php
File metadata and controls
30 lines (26 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/* ----------- File Handling ------------*/
/**
*Eng: File Handling is the ability to read and write files
* on the server.
* PHP has built in functions for reading and writing files.
*
* Pt: Por: File Handling é a capacidade de ler e gravar arquivos no servidor.
* O PHP possui funções integradas para leitura e gravação de arquivos.
**
*/
//read file | lendo arquivos ou ficheiros
$file = '14_users.txt';
if(file_exists($file)){
// echo(' - '.readfile($file)); //print-output list | imprimir a lista
$handle = fopen($file, 'r');
$contents = fread($handle, filesize($file));
fclose($handle);
echo $contents.'<br>';
}else {
$handle = fopen($file, 'w');
$contents = 'Brand'. PHP_EOL .'Sara' .PHP_EOL . 'Mike';
fwrite($handle, $contents);
fclose($handle);
}
?>