Now, you have got to know the way of making, opening, reading and above all writing the data in a file.
It is the right time to know how to delete a file. It can be done by using the function “unlink”.
File Unlink in PHP
By checking the directory, you can get to know whole files of that directory. It is due to the reason that the used application will show you all the contents. It can be think that these filenames are like links which makes a connection between the files and the directory.
On the other hand, if we use a command unlink then the require file will not be seen, it can say that it will get deleted.
In case, you need to delete a file then you have to confirm that this file is not unlocked. If it is open then use fclose to close the file.
Unlink Function in PHP
The name of our file is newfile.txt.
Code of PHP
$fh = fopen($mynewFile, 'w') or die("file can not open");
In order to delete the file named as newfile.txt, we have to use a command. From the directory, we select the name and then we will give the code.
Code of PHP
By using this code, the file“newfile.txt” will be deleted.
The function unlink is used for deleting the file. Make it certain that you are going to delete a file which is no longer in use.