Server Side
Scripting
PHP - File Handling
& File Upload
File Handling
Opening a file in PHP
In PHP, the fopen() function is used to open a file.
The function takes two parameters:
• Filename (Path): This is the first parameter, and it specifies the name of the file to be
opened. This can include the full path to the file.
• Mode: This is the second parameter, and it specifies the mode in which the file should be
opened. The mode determines whether the file will be opened for reading, writing, or both,
as well as whether the file should be created if it does not exist.
Reading From a File
• Using fgets()
Reading From a File
2. Using fread()
Reading From a File
3. Using file()
Writing to a File
Example:
Closing the open file
It is important to close files after you have finished reading
from or writing to them.
Syntax:
Appending to a File
Different modes for opening a file
Problem
Solution
File Upload
File Upload -
File Upload
Additional Topic - Method Overriding
Thank you!