使用 php header 和 readfile 函数下载 word 文件时出现问题。在 Mozilla Firefox 中下载时响应良好,但在使用 google chrome 和 IE 时效果不佳。请指导我解决此问题。
这是我的代码:
switch(strtolower($ext))
{
case "doc": $ctype="application/msword"; break;
case "docx": $ctype="application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
default: $ctype="application/octet-stream";
}
header('Content-Description: File Transfer');
//header("Content-type: application/octet-stream");
header("Content-Type: ".$ctype." ");
header('Content-Disposition: attachment; filename='.basename($rw['FINALDOCNAME']));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Pragma: private');
header('Content-Length: ' . filesize($rw['FINALDOCNAME']));
ob_clean();
flush();
readfile($filepath);