File handling is an important activity of all web application development process. Files are processed for different tasks using the following events:
● PHP Open a File,
● PHP Read a File,
● PHP Close a File,
● PHP Write a File,
● PHP Appending a File and
● PHP uploading a File.
PHP Open a File
fopen() is a system function available in PHP. This function helps to open a file in the server. It contains two parameters one for the file and the other one specifies in which mode the file should be opened (Read/Write).
$file_Object= fopen(“FileName”, “Read/WriteMode”) or die(“Error Message!”);
$myfile = fopen(“Student.txt”, “r”) or die(“Unable to open file!”);
The fread() function reads from an open file. The file object comes from fopen function.
The fclose() function is used to close an opened file. The file object comes from fopen function.
$myfile = fopen(“student.txt”, “r”); // some code to be executed....
The fwrite() function is used to write to a file.