Deletes a file
Syntax
unlink(string $filename, resource $context = ?): bool
Parameters
filename
Path to the file.
If the file is a symlink, the symlink will be deleted. On Windows, to delete a symlink to a directory, rmdir() has to be used instead.
context
A context stream resource.
Return
Returns true on success or false on failure.
Examples
1 · filename
<? $filename = 'unlink.txt'; $mode = 'a'; $handle = fopen($filename, $mode); $string = 'unlink'; fwrite($handle, $string); fclose($handle); $return = unlink($filename); echo $return; ?>
1
2 · context
<? $filename = 'unlink.txt'; $mode = 'a'; $handle = fopen($filename, $mode); $string = 'unlink'; fwrite($handle, $string); fclose($handle); $context = stream_context_create(); $return = unlink($filename, $context); echo $return; ?>
1