English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Filesystem Reference Manual
The unlink() function can delete a file, and returns true on success, 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 ("Delete $file successfully"); } ?>
Output Result
delete /PhpProject/php/sample.txt deleted successfully
<?php $fh = fopen("/PhpProject/test.html", "a"); fwrite($fh, "<h1> Hello world! </h1"); fclose($fh); unlink("/PhpProject1/test.html"); ?>
Output Result
file deleted successfully