What is the purpose of setting the Content-type and Content-Disposition headers in PHP when opening a file in Excel?
Setting the Content-type header in PHP tells the browser what type of content is being sent, in this case, Excel data. Setting the Content-Disposition header with a value of "attachment; filename=filename.xls" prompts the browser to download the file instead of displaying it in the browser window. This ensures that the Excel file is downloaded and opened in the user's Excel application.
<?php
// Set headers for Excel file download
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=filename.xls');
// Output Excel data
echo "Your Excel data here";
?>