我正在尝试使用“PHPWord”下载 docx 文件。
如果我尝试将文件保存到服务器上,它工作正常。但是,如果添加标题以下载它,则文件将以损坏的形式显示。
注意:我使用 openOffice 打开它。
这是我的代码:
$document->save($doc);
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header("Content-Disposition: attachment; filename=CV.docx");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($doc));
readfile($doc);
谁能告诉我可能是什么问题?