English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The unlink() function can delete a file, returning true on success and false on failure.
bool unlink ( string $filename [, resource $context ] )
This function can delete the filename, similar to the Unix C unlink() function.
<?php $file = "/PhpProject/php/sample.txt"; if(!unlink($file)) { echo("Error occurred while deleting $file"); } else { echo("Successfully deleted $file"); } ?>
Output result
Successfully deleted /PhpProject/php/sample.txt
<?php $fh = fopen("/PhpProject/test.html", "a"); fwrite($fh, "<h1>Hello world!</h1>"); fclose($fh); unlink("/PhpProject1/test.html"); ?>
Output result
file deleted successfully