我正在生成docx并从服务器下载.
private static function downloadFile($fileDir)
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($fileDir));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileDir));
readfile($fileDir);
}
Run Code Online (Sandbox Code Playgroud)
这是保存功能.如果我从服务器打开临时目录中的文件,它的工作原理.但下载后,我有错误"文件已损坏".我尝试恢复文件,然后恢复所有确定.错误在哪里?