In this article, you will learn how to delete or unlink a file in PHP. The unlink() function in PHP deletes a file.
what is the syntax of the UNLINK function in php?
unlink(filename, context)
Parameter Values
Parameter | Description |
---|---|
filename | Required. Specifies the path to the file to delete |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream |
examples of the UNLINK function
Example 1. In this example, we delete a file.
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
unlink("test.txt");
?>