PHP unlink() Function
Definition
The unlink() function deletes a file.
Syntax
PHP unlink() Function has the following syntax.
unlink(filename,context)
Parameter
Parameter | Is Required | Description |
filename | Required. | File to delete |
context | Optional. | Context of the file handle. |
Return
This function returns TRUE on success, or FALSE on failure.
Example
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// w w w .ja v a 2 s .c o m
$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().