在php中下载后无法打开.doc文件

在php中下载后无法打开.doc文件,php,ms-word,doc,Php,Ms Word,Doc,我有一个用php下载文件的脚本,它工作得很好。但当我下载一个.doc类型的文件并在MS Word中打开它时,它表示我必须选择一种编码,并且大多数文本都是这种格式: -Lß{Gÿÿÿÿÿÿÿ•ߩߩ((ÐÐÿÿÿÿÿÿÿÿÿÿÿ,ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ 这是我的标题: header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"

我有一个用php下载文件的脚本,它工作得很好。但当我下载一个.doc类型的文件并在MS Word中打开它时,它表示我必须选择一种编码,并且大多数文本都是这种格式:

-Lß{Gÿÿÿÿÿÿÿ•ߩߩ((ÐÐÿÿÿÿÿÿÿÿÿÿÿ,ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

这是我的标题:

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

您必须添加
标题('Content-type:application/octet-stream');

不确定您的
$mtype=application/msword
应该做什么

并将
标题(“内容处置:附件;文件名=\”$newFile\”);
更改为
标题(“内容处置:附件;文件名=”。$newFile.);

在标题之后,只需使用:

ob_clean();
ob_end_flush();
readfile($file_path);
exit;

正如你所说,我改变了,但它做了同样的事情。在我的头之后,我得到了以下代码:$file=@fopen($file_路径,“rb”);if($file){while(!feof($file)){print(fread($file,1024*8));flush();if(connection_status()!=0){@fclose($file);die();}@fclose($file)}