What are the best practices for handling file downloads and redirects in PHP scripts to avoid conflicts?

When handling file downloads and redirects in PHP scripts, it is important to ensure that there are no output sent to the browser before initiating the download or redirect. To avoid conflicts, use the `header()` function to set appropriate headers for file downloads and redirects before any output is generated.

<?php
// For file download
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.txt"');
readfile('path/to/example.txt');
exit;

// For redirect
header('Location: http://www.example.com');
exit;
?>