How can PHP's built-in functions like unlink and readfile be used in conjunction to efficiently manage downloaded files on the server?

When managing downloaded files on the server, it is important to efficiently delete files that are no longer needed to free up server space. PHP's built-in functions unlink can be used to delete files, while readfile can be used to efficiently output file contents to the browser for download. By combining these functions, you can easily delete files after they have been downloaded by the user.

// Download file to the browser
$file = 'path/to/file.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Length: ' . filesize($file));
readfile($file);

// Delete the file after download
unlink($file);