gpt4 book ai didi

php - 用于下载 Microsoft Word 和 Excel 文件的 http header

转载 作者:太空狗 更新时间:2023-10-29 13:19:15 25 4
gpt4 key购买 nike

如果我默认在文件名中命名它,我可以成功下载我的microsoft word。但是如果我使用 $variables 来命名它。文档扩展名将是未知的。

示例:

$No = 1; 
$Name = 'John';
$Test = 'Science';

//Download header
$document->save($doc);
header('Content-Description: File Transfer');
header('Content-Type: application/msword');
header("Content-Disposition: attachment; filename='$No_$Name_$Test.docx");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($doc));
ob_clean();
flush();
readfile($doc);

因此,如果我将文件名重命名为变量。下载的文件将没有 docx 扩展名。任何人都可以提供建议吗?

谢谢

最佳答案

正确的标题是

对于 Excel (*.xlsx):

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $fileName . '"');

对于 Word (*.docx):

header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename="' . $fileName . '"');

关于php - 用于下载 Microsoft Word 和 Excel 文件的 http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11487365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com