PHP: Delete File / Erase File / Remove File

As long as the owner of the php script has the necessary privilege to delete a file, the php script has the ability to delete it.

To delete a file with PHP, use the unlink() function:

unlink('tmpfile.txt') or die('Unable to delete the file');

It returns true if the deletion is successful and false otherwise.

Scroll to Top