Are there any best practices or tutorials available for handling file downloads in PHP to ensure a smooth user experience?

When handling file downloads in PHP, it is important to set the appropriate headers to ensure a smooth user experience. This includes setting the content type, content length, and disposition headers. Additionally, it is recommended to use file streaming to efficiently handle large file downloads.

<?php
$file = 'example.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);
exit;
?>