What is the best way to automatically start a download from a PHP script?

To automatically start a download from a PHP script, you can use the `header()` function to send the appropriate HTTP headers to trigger the download prompt in the browser. Set the `Content-Type` header to the MIME type of the file you are downloading, and use `Content-Disposition` header with the `attachment` value to prompt the browser to download the file instead of displaying it. You can also set the `Content-Length` header to specify the size of the file being downloaded.

<?php
$file = 'example.pdf';
$filename = 'downloaded_file.pdf';

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . filesize($file));

readfile($file);
exit;
?>