How to Delete a file in PHP

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In the last tutorial, we wrote to a log file called “log.txt” in PHP.  Now we use PHP to delete this file.  Simple do…

unlink(‘log.txt’);

in PHP.  And the file will be deleted.

This function will return TRUE on success or FALSE on failure. In order for this to be successful, the file must be closed and the web app must have write permission on the folder that contains the file.