How can PHP be used to control the download location of a file on a website?

When serving files on a website using PHP, you can control the download location by setting the appropriate headers in the response. By specifying the "Content-Disposition" header with a value of "attachment; filename=yourfilename.extension", you can prompt the browser to download the file instead of displaying it in the browser window. This allows you to specify the default download location for the user.

<?php
// Set the file path
$file = 'path/to/yourfile.pdf';

// Set the headers
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="yourfile.pdf"');

// Output the file
readfile($file);
?>