The unlink () function deletes a file.
If the call succeeds, true is returned. If the call fails, false is returned.
Syntax
Unlink (filename, context)
Parameter description
Filename is required. Specifies the file to be deleted.
Context is optional. Specifies the file handle environment. Context is a set of options for modifying stream behavior.
<? Php tutorial
$ File_delete = "home/meeta/my. php ";
If (unlink ($ file_delete )){
Echo "The file was deleted successfully.", "n ";
} Else {
Echo "The specified file cocould not be deleted. Please try again.", "n ";
}
?> The following code checks whether a file exists.
<? Php
$ Myfile = "./test1.txt ";
If (file_exists ($ myfile )){
$ Result = unlink ($ myfile );
Echo $ result;
}
?>
The file_exists () function checks whether a file or directory exists.
If the specified file or directory exists, true is returned; otherwise, false is returned.
Syntax
File_exists (path)