douyouzheng2209 2017-06-12 06:49
浏览 119

PDF-使用PHP下载 - > ERR_CONTENT_LENGTH_MISMATCH

I would like to download a PDF via PHP from my server, which is also uploaded via PDF. Although it works with some files I get the following error message with individual files:

ERR_CONTENT_LENGTH_MISMATCH

This is my download function:

if($_GET['funktion'] == 'downloadallgemein')
 {

        $filename = basename($dateiname);
        $path = '/kunden/261105_71522/webseiten/dev.delst/uploads/'.$filename.''; // the file made available for download via this PHP file
        if (file_exists($path)) {
                $mm_type="application/octet-stream"; // modify accordingly to the file type of $path, but in most cases no need to do so

                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: " . $mm_type);
                header("Content-Length: " .(string)(filesize($path)) );
                header('Content-Disposition: attachment; filename="'.basename($path).'"');
                header("Content-Transfer-Encoding: binary
");

                readfile($path); // outputs the content of the file

                exit();
        }

        else
        echo'Datei wurde nicht auf dem Server gefunden';
 }  

If I remove header("Content-Length: " .(string)(filesize($path)) ); the download works, but the PDF file is then broken and can not be opened.

The path is correct and the file is located on the server. So the upload works..

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • drfm55597 2017-06-12 07:42
    关注

    header('Content-Type: application/pdf');

    header('Content-Disposition: attachment; filename="' . basename($filename) . '"');

    header('Content-Length: ' . filesize($filename));

    readfile($filename);

    I used this headers for downloading pdf in my php file

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度