PHP | Unlink() function
The unlink() function is an inbuilt function in PHP that is used to delete the file from a directory. If the file function executes successfully and deletes the file then it returns true otherwise it returns false.
Syntax
bool unlink ( string $filename [, resource $context ] )
$filename
Required. Specifies the file which has to be deleted.
$context
Optional. Specifies the context of the filehandle which can be used to modify the nature of the stream.
<?php
$file = "demo.txt";
if (!unlink($file))
{
echo ("Error deleting $file");
}
else
{
echo ($file."file deleted successfully");
}
?>
Note: For the webserver user must have write permissions to the directory for using the unlink() function.