Here is the general form of deleting a file in PHP.
Before delete any file in PHP, let's first see the screenshot of C:\xampp\htdocs\ directory folder. Below is the screenshot of this directory.
As you can see, there is a file named codescracker is present inside the current directory which is a textual file.
Now, here is an example of deleting a file in PHP
<html> <head> <title>Deleting a file in PHP</title> </head> <body> <?php $file_name = "codescracker.txt"; echo "<p>Deleting the file <b>".$file_name."</b>.....</p>"; unlink($file_name); echo "<p>File deleted successfully.</p>"; ?> </body> </html>
Here is the sample output produced by the above deleting file example code in PHP.
And here is the screenshot of the current directory folder.
As you can see, the file codescracker.txt is deleted from the current directory.