Like other languages, PHP also has file handling as an important part of web applications that allows us to manipulate files using several functions such as creating, reading, writing, deleting and so on.

The following is a list of functions that can be used to manipulate the files in PHP:

image
Cautions

You need to be very careful when manipulating files because if you do something wrong then a lot of damage can be happen, like deleting the contents of the file by mistake, editing the wrong file, filling garbage data in the hard-drive, writing the content in the wrong file and so on.

Now let's explain all the functions briefly.

Create and Open

The function fopen() is used to open as well as create a file.

Syntax example:

Close

The function fclose() is used to close an open file after finishing your work.

Syntax example: Read

The function fread() is used to read the contents of the file. It needs two arguments, the resource and file size.

Syntax example: Write

The function fwrite() is used to write the contents of the string into a file.

Syntax example: Append

The function fopen() is also used to append the contents into a file, but in a different way. It uses "a" or "a+" mode in fopen() the function.

Syntax example: Delete

The function unlink() is used to delete the file.

Syntax example: The details about all the functions will be discussed in the next part of this article and that will be here as soon as possible, until then.

Thank you, keep learning and sharing.