What function can be used in PHP to delete a file from a directory?
To delete a file from a directory in PHP, you can use the `unlink()` function. This function takes the file path as an argument and removes the specified file from the directory. It is important to note that once a file is deleted using `unlink()`, it cannot be recovered, so it is recommended to double-check the file path before calling this function.
$file_path = 'path/to/file.txt';
if (file_exists($file_path)) {
if (unlink($file_path)) {
echo 'File deleted successfully.';
} else {
echo 'Unable to delete file.';
}
} else {
echo 'File does not exist.';
}