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?