我想通过 PHP 从我的服务器下载 PDF,该 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';
}
如果我删除header("Content-Length: " .(string)(filesize($path)) ); 下载有效,但 PDF 文件随后损坏且无法打开。
路径正确,文件位于服务器上。所以上传工作..
我究竟做错了什么?