PDF-Download with PHP - > ERR_CONTENT_LENGTH_MISMATCH

时间:2017-06-12 06:49:29

标签: php pdf downloading content-length http-content-length

我想通过PHP从我的服务器下载PDF,也可以通过PDF上传。虽然它适用于某些文件,但我收到以下错误消息:单个文件:

ERR_CONTENT_LENGTH_MISMATCH

这是我的下载功能:

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\n");

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

                exit();
        }

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

如果我删除标题(“Content-Length:”。(字符串)(filesize($ path))); 下载有效,但PDF文件会被破坏且无法打开

路径正确,文件位于服务器上。所以上传工作..

我做错了什么?

1 个答案:

答案 0 :(得分:0)

  

标题('Content-Type:application / pdf');

     

header('Content-Disposition:attachment; filename =“'。basename($ filename)。'”');

     

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

     

的ReadFile($文件名);

     

我使用此标题在我的php文件中下载pdf