What role does the dot operator play in concatenating variables with strings in PHP headers for file downloads?
When concatenating variables with strings in PHP headers for file downloads, the dot operator (.) is used to combine the variable values with the string content. This allows us to dynamically generate file names or content types based on variables. It is important to properly concatenate and format the header content to ensure the file is downloaded correctly by the browser.
<?php
// Set variables for file name and content type
$filename = "example.txt";
$content_type = "text/plain";
// Set headers for file download
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: " . $content_type);
// Output file content
echo "This is the content of the file.";
?>