File Handling in PHP
Opening and Closing Files
Files are opened in PHP using the fopen command. The command takes two parameters, the file to be opened, and the mode in which to open the file. The function returns a file pointer if successful, otherwise zero (false). Files are opened with fopen for reading or writing.
$fp = fopen("myfile.txt", "r");
If fopen is unable to open the file, it returns 0. This can be used to exit the function with an appropriate message.
if ( !($fp = fopen("myfile.txt", "r") ) )
exit("Unable to open the input file.");