How can PHP code be modified to always prompt the user to save a file for download, rather than opening it in the browser?

To always prompt the user to save a file for download rather than opening it in the browser, you can set the appropriate headers in the PHP code. This can be achieved by setting the Content-Disposition header to "attachment" along with a filename. This way, the browser will always prompt the user to save the file instead of displaying it.

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

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