PHP File Open/Read/Close

In this chapter we will see how we can open, read and close a file using PHP functions.

fopen() – Open a file in PHP

fopen() function is used to open a file in PHP. This function accepts two parameters.

  • One parameter will be passed as a filename
  • And the second parameter will be used for the filemode.

Example

fread() – Read a file in PHP

Then fread() function in PHP, is used to read the file. It accepts two parameters:

  • First parameter will be passed as a filename.
  • And the second parameter specify the file size.

fclose() – Close a file in PHP

This function is used to close an opened file. It is a good practice to close all the opened file because it saves the server resources and makes the website fast.

The fclose() function accepts only one parameter which will be just the filename only.

 

 

Leave a Reply

Your email address will not be published.