How to delete a single file in php: You can use the unlink() function to delete the file. Returns true if file deletion is successful. If deletion of the file fails, false is returned. The specific usage method is: [unlink($filename)].
The unlink() function deletes files. If successful, the function returns TRUE. On failure, returns FALSE.
(Recommended tutorial: php graphic tutorial)
Syntax:
unlink(filename,context)
Parameters:
filename Required. Specifies the files to be deleted.
context Optional. Specifies the environment for a file handle. context is a set of options that can modify the behavior of the stream.
(Learning video recommendation: php video tutorial)
Code implementation:
<?php $file = "test.txt"; if (!unlink($file)) { echo ("Error deleting $file"); } else { echo ("Deleted $file"); } ?>
The above is the detailed content of How to delete a single file in php. For more information, please follow other related articles on the PHP Chinese website!