File handling simply means to open a file and to process it according to the required tasks. PHP facilitates several functions to create, read, write, append, delete and close files.
To open a file in PHP, fopen() function is used.
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
To close a file in PHP, fclose() function is used.
ool fclose ( resource $handle )
To read a file in PHP, fread() function is used.
string fread (resource $filename , int $filesize )
To write a file in PHP, fwrite() function is used.
int fwrite ( resource $handle , string $string )
To delete a file in PHP, unlink() function is used.
bool unlink ( string $filename [, resource $context ] )
<!DOCTYPE html> <html> <body> <?php $samplefile = fopen("phpfile.txt", "r"); echo fread($samplefile,filesize("phpfile.txt")); fclose($samplefile); ?> </body> </html>