First and the most important thing is to make a file.
Trouble in creating a file in PHP
The command which is used for opening a file is same for making a file. That is why; it creates trouble for new users.
The code for opening a file is fopen but it cab be used for making a file. The reason is that if there is no file of a specific name during the execution of a function, then the same code creates a file. So, fopen only makes a file when it can not find it.
What is the way of making a file?
Two types of information are necessary for working in a correct way. The first thing is to give the correct name of the specific file which you want to open. The other thing is to inform about the real purpose of opening that file. Your purpose can be reading, editing or writing in a file. As we have to make a file, so we have to clarify our aim.
Code of PHP
$newFileHandle = fopen($newFileName, 'w') or die("file can not open ");
We have created a file with the name “newfile.txt” in the path where the code of PHP exists. It will be seen that this file is not present here, so it make a new file of this name. Here, we are going to explain you the code:
? $ourFileName = “newfile.txt”
We will make a file in PHP having the name “newfile.txt”. It will be saved in a variable $newFileName.
? $newFileHandle = fopen($newFileName, ‘w’) or die(“file can not open”);
This part of the code has two sections. The first one is to make use of the function names fopen with assigning it 2 arguments. These are new file name and ‘w’ as a character.
The other is file handle. It gives us permission to make changes in the file. It will be saved in a variable $newFileHandle.
We seal the open file. The function fhandle gets the handle of the file which is being closed.
Authorization in PHP
On case, you have got some errors while running a file then you have to notice the permission granted by PHP. This authorization can be completed by using a program of FTP. It runs a command CHMOD, which give permission to the file to write.