How to delete a file in PHP?

To delete a file in PHP, you can use the unlink() function. Here's an example:

$file = 'path/to/file.txt'; if (file_exists($file)) { unlink($file); echo 'File deleted successfully.'; } else { echo 'File does not exist.'; }

In the example above, the file_exists() function is used to check if the file exists before attempting to delete it. If the file exists, the unlink() function is called to delete the file. If the file does not exist, an appropriate message is displayed.

Note: Make sure that the PHP process has proper permissions to delete the target file.