What is the difference between using include() and readfile() when downloading files in PHP?

When downloading files in PHP, the main difference between using include() and readfile() is that include() will execute the file's PHP code before outputting it, while readfile() simply reads the file and outputs its contents. If you are downloading a file that contains PHP code that you want to execute, you should use include(). However, if you are downloading a file that is meant to be directly downloaded (such as an image or a PDF), you should use readfile() to avoid any unexpected PHP code execution.

// Using readfile() to download a file directly without executing any PHP code
$file = 'path/to/file.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
readfile($file);
exit;