How can PHP be used to create a download script that allows for custom file names during download?

To create a download script in PHP that allows for custom file names during download, you can use the `header()` function to set the `Content-Disposition` header with the desired file name. This will prompt the browser to download the file with the specified name.

<?php
$file = 'path/to/your/file.txt';
$customFileName = 'custom_filename.txt';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . $customFileName . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
} else {
    echo 'File not found.';
}
?>