PHP unlink() Function

Definition

The unlink() function deletes a file.

Syntax

PHP unlink() Function has the following syntax.

unlink(filename,context)

Parameter

ParameterIs RequiredDescription
filenameRequired.File to delete
contextOptional.Context of the file handle.

Return

This function returns TRUE on success, or FALSE on failure.

Example

Files are deleted using unlink().

To delete files, pass a filename string as the only parameter to unlink(). To delete directories, you need rmdir().


<?PHP//  w w w .ja v a 2  s  .c o m
      $filename = "c:/abc/test.txt";
      if (unlink($filename)) {
             print "Deleted $filename!\n";
      } else {
             print "Delete of $filename failed!\n";
      }
?>

If you have a file opened with fopen(), you need to fclose() it before you call unlink().





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions