Comandi/funzioni per operare con i file.
Aprire e chiudere
$handle | fopen() | $nome $modo |
… |
$bool | fclose() | $handle | … |
Estrarre informazioni
$bool | file_exists() | $nome | Controlla se il file esiste |
$str | file_type() | $nome | Restituisce fifo / char / dir / block / link / file / socket / unknown |
$bool | is_file() | $nome | Controlla se è un file |
$bool | is_readable() | $nome | Controlla se il file esiste ed è leggibile |
$bool | is_writable() | $nome | Controlla se il file esiste ed è scrivibile |
Leggere e scrivere
$bool | fflush() | $handle | Forza la scrittura dei dati in sospeso |
$str | fgetc() | $handle | Legge un carattere |
$str | fgets() | $handle | Legge una riga, al massimo 1024 caratteri |
$str | fgets() | $handle $num |
Legge $num-1 caratteri, se ci sono |
$str | file_get_contents() | $handle | Legge l’intero file e restituisce una stringa |
$array | file() | $handle | Legge l’intero file e restituisce un array delle righe |
$str | fread() | $handle $num |
Legge $num byte, se ci sono |
$num | fwrite() fputs() |
$handle $str |
Scrive la stringa nel file |
Operare con il puntatore nel file
$bool | feof() | $handle | Controlla se il file è finito |
$num | fseek() | $handle $num |
Posiziona il puntatore nel file |
$num | fseek() | $handle $num $whence |
SEEK_SET, dall’inizio (default) SEEK_CUR, dalla posizione attuale SEEK_END, dalla fine |
$num | filesize() | $nome | Restituisce il numero di byte del file |
$num | ftell() | $handle | Restituisce la posizione del puntatore nel file |
$bool | ftruncate() | $handle $num |
Tronca il file alla posizione data |
$bool | rewind() | $handle | Riporta il puntatore all’inizio del file |
Copia, rinomina, elimina
$bool | copy() | $nome1 $nome2 |
Copia il file |
$num | readfile() | $nome | Legge tutto il file e lo passa all’output |
$bool | rename() | $nome1 $nome2 |
Rinomina il file |
$bool | unlink() | $nome | Elimina il file |
Altro
$str | md5_file() | $nome | … |