我有一个用php下载文件的脚本,它工作得很好。但当我下载一个.doc类型的文件,并在MS Word中打开它时,它会提示我必须选择一种编码,而大多数文本都是这种格式:
--- L ß{ ß{ Gü ² ÿÿ ÿÿ ÿÿ • Ê Ê ( ( Ð Ð Ð Ä ÿÿÿÿ ”¬ ”¬ ”¬ ”¬ T. èM ” ”- â |W ’W ’W ’W ’W ý÷ ý÷ ý÷ è ---
下面是我的标题:
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$newFile\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
$mtype = application/msword发布于 2012-03-31 05:30:24
您必须添加header('Content-type: application/octet-stream');。
不确定你的$mtype = application/msword应该做什么...
并将header("Content-Disposition: attachment; filename=\"$newFile\"");更改为header('Content-Disposition: attachment; filename="'.$newFile'."');
在头文件之后只需使用:
ob_clean();
ob_end_flush();
readfile($file_path);
exit;https://stackoverflow.com/questions/9950254
复制相似问题