PHP unlink() Function

Definition and Usage

The unlink() function deletes a file.

Returns true on success, false on failure.

Syntax

unlink(filename,context)
Parameter Description
filename Required. Specifies the file to be deleted.
context Optional. Specifies the file handle environment. Context is a set of options that modify the behavior of a stream.

Tips and Comments

Note:for context Support was added in PHP 5.0.0.

Example

<?php
$file = "test.txt";
if (!unlink($file))
  {
  echo("Error deleting $file");
  }
else
  {
  echo("Deleted $file");
  }
?>