0% found this document useful (0 votes)
8 views16 pages

PHP - File Handling & File Upload

The document provides an overview of file handling in PHP, detailing how to open, read, write, and close files using functions like fopen(), fgets(), fread(), and file(). It also discusses different modes for opening files and emphasizes the importance of closing files after use. Additionally, it briefly mentions file upload and method overriding as related topics.

Uploaded by

jumpyturtle8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views16 pages

PHP - File Handling & File Upload

The document provides an overview of file handling in PHP, detailing how to open, read, write, and close files using functions like fopen(), fgets(), fread(), and file(). It also discusses different modes for opening files and emphasizes the importance of closing files after use. Additionally, it briefly mentions file upload and method overriding as related topics.

Uploaded by

jumpyturtle8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

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!

You might also like