The unlink() function deletes a file.
PHP unlink() Function has the following syntax.
unlink(filename,context)
Parameter | Is Required | Description |
filename | Required. | File to delete |
context | Optional. | Context of the file handle. |
This function returns TRUE on success, or FALSE on failure.
Files are deleted using unlink().
To delete files, pass a filename string as the only parameter to unlink(). To delete directories, you need rmdir().
<?PHP
$filename = "c:/abc/test.txt";
if (unlink($filename)) {
print "Deleted $filename!\n";
} else {
print "Delete of $filename failed!\n";
}
?>
If you have a file opened with fopen(), you need to fclose() it before you call unlink().