First a file has to exist!
In this lesson you will learn how to create a file.
In PHP, a file is created using a command that is also used to open files.
This is a little confusing.
The fopen function is used to open files.
If fopen does not find the file specified (does not exist), it will create that file.
The fopen function needs two information to operate correctly.
(i.e. read, write, append etc).
The file "testFile.txt" should be created in the same directory where this PHP code resides.
When PHP saw that "testFile.txt" does not exists and fopen created that file.
Let's look closely at the codes.
Here we create the name of our file, "testFile.txt" and store it into a PHP String variable $FileName.
This bit of code actually has two parts. First we use the function fopen and give it two arguments: (1) File name and (2) We indicate that we want to write by character "w".
Then, the fopen function returns what is called a file handle.
It will allow us to manipulate the file and we save the file handle into the $FileHandle variable.
We close the file that was opened. fclose takes the file handle that is to be closed.
Note For more detail please see Php Manual at http://www.php.net