【问题标题】:php docx file retrieval causing unreadable contentphp docx文件检索导致不可读的内容
【发布时间】:2020-01-31 21:38:44
【问题描述】:

我正在尝试通过 php 提供 docx 文件。它可以工作,但是在打开时我收到一条错误消息,说文件中有不可读的内容,我相信吗?

 $attachment_location = $_SERVER['DOCUMENT_ROOT']."FILEPATH";
    if (file_exists($attachment_location)) {

        header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
        header("Cache-Control: public"); // needed for internet explorer
header('Content-type: application/vnd.openxmlformats- officedocument.wordprocessingml.document');
        header("Content-Transfer-Encoding: Binary");
        header("Content-Length:".filesize($attachment_location));
        header("Content-Disposition: attachment; filename=FILENAME.docx");
        readfile($attachment_location);
        die();        
    } else {
        die("Error: File not found.");
    } 

我尝试了一些建议,但找不到解决方案?谁能看出明显的遗漏?

【问题讨论】:

    标签: php docx


    【解决方案1】:

    只需添加 ob_clean();在 if 语句的开头。

    ob_clean();
    

    【讨论】:

    • 是的,对不起,我试图接受答案,但太早了
    猜你喜欢
    • 1970-01-01
    • 2020-01-22
    • 2016-10-06
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 2022-09-28
    • 1970-01-01
    相关资源
    最近更新 更多