What are best practices for setting the correct headers when displaying a PDF file in a browser using PHP?

When displaying a PDF file in a browser using PHP, it's important to set the correct headers to ensure the file is rendered correctly. This includes setting the Content-Type header to 'application/pdf' and the Content-Disposition header to 'inline; filename=filename.pdf'. Additionally, it's recommended to use ob_clean() and flush() functions to prevent any output buffering issues.

<?php
// Set the correct headers
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=filename.pdf');

// Clear output buffer
ob_clean();
flush();

// Output the PDF file
readfile('path/to/your/file.pdf');
?>