unlink

boolean unlink(string path) 

Deletes a file.

Returns:

TRUE on success; FALSE on error

Description:

unlink() deletes a file. If the file cannot be deleted, the function returns FALSE and generates an error.

Note:

Lack of adequate permissions or file locking are the most common reasons why calls to unlink() fail.

Example:

Delete a file
<?php 
$filepath = "/tmp/test.txt"; 

if (! unlink ($filepath)) {
    echo ("Couldn't delete file"); 
} else {
     echo ("Removed $filepath"); 
} 
?> 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.