【问题标题】:Cant open .doc file after download in php在php中下载后无法打开.doc文件
【发布时间】:2012-03-30 20:50:31
【问题描述】:

我有一个用 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

【问题讨论】:

    标签: php ms-word doc


    【解决方案1】:

    您必须添加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;
    

    【讨论】:

    • 我按照你说的改变了,但它的效果是一样的。在我的标题之后,我得到了这个代码: $file = @fopen($file_path,"rb"); if ($file) { while(!feof($file)) { print(fread($file, 1024*8));冲洗(); if (connection_status()!=0) { @fclose($file);死(); } } @fclose($file); }
    猜你喜欢
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2016-12-05
    相关资源
    最近更新 更多