<< PHP Rename a File | PHP Tutorials | PHP Upload a File >>

PHP Delete a File - unlink()

The unlink() function is what you need to use to delete a file. It only requires one parameter, the file name to delete. Here is an example:

<?php
unlink('example.txt');
?>

Now you have to be careful when trying to delete a file. Something could go wrong (such as a typing error) and you could end up deleting the wrong file! There is no way to get it back either :S

<< PHP Rename a File | PHP Tutorials | PHP Upload a File >>