PHP unlink() Function
In this chapter you will learn:
- Definition for PHP unlink() Function
- Syntax for PHP unlink() Function
- Parameter for PHP unlink() Function
- Return for PHP unlink() Function
- Example - Delete a file
Definition
The unlink() function deletes a file.
Syntax
PHP unlink() Function has the following syntax.
unlink(filename,context)
Parameter
Parameter | Is Required | Description |
filename | Required. | File to delete |
context | Optional. | 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//from j a v a 2s.c om
$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().
Next chapter...
What you will learn in the next chapter:
- Definition for PHP vfprintf() Function
- Syntax for PHP vfprintf() Function
- Parameter for PHP vfprintf() Function
- Additional format for PHP printf() Function
- Return for PHP vfprintf() Function
- Example - Write some text to a text file named "test.txt"
- Example - Write some text to a file
- Example - Use of placeholders
- Example - Using printf() to demonstrate all possible format values
Home » PHP Tutorial » PHP File Functions