使用php头文件和readfile函数下载word文件时出现问题。 在Mozilla Firefox中下载时反应良好,但使用谷歌浏览器和IE时效果不佳。请指导我解决此问题。如何在chrome和IE上使用php下载word文件
这里是我的代码:
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);
是否检查实际的文件是否存在?为什么不检查'filesize'和'readfile'返回值以确保它们是预期的。 – 2013-03-05 07:44:29