我有一个用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
您必须添加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;