What are the best practices for allowing users to download files while still displaying the original page content in PHP?

When allowing users to download files in PHP, it's important to use the proper headers to initiate the file download without disrupting the original page content. One way to achieve this is by using a combination of PHP headers and readfile() function to send the file to the user's browser for download while still displaying the original page content.

<?php
// Set the proper headers to initiate file download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.pdf"');

// Read the file and output it to the browser
readfile('path/to/your/file/example.pdf');

// Display the rest of the page content
echo '<h1>Welcome to our website!</h1>';
?>