Are there any best practices for prompting the "save file" dialog when downloading a file using PHP?

When downloading a file using PHP, you can prompt the "save file" dialog by setting the appropriate headers in the response. This involves setting the Content-Type header to the appropriate MIME type of the file and setting the Content-Disposition header to "attachment; filename=yourfilename.extension". This will force the browser to show the "save file" dialog instead of attempting to display the file in the browser.

<?php
// Set headers
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=example.txt");

// Output the file content
echo "This is the content of the file.";
?>