【发布时间】:2018-08-08 10:50:10
【问题描述】:
我有一个 PHP 脚本,它按字节范围提供 PDF 文件的部分内容。
如果收到 HTTP HEAD 请求,它应该发回标头(包括 PDF 文件大小),而不是实际的文件内容。我试过这个:
header('HTTP/1.1 200 OK');
header('Content-Type: application/pdf');
header('Accept-Ranges: bytes');
header('Content-Length: '.filesize($Pathname));
die;
问题是某些东西(我假设 Web 服务器 == LiteSpeed)将 Content-Length 标头替换为 Content-Length: 0 - 这违背了整个目的。
谁能建议我应该做什么?谢谢
【问题讨论】:
-
你检查过
$Pathname是否正确吗? -
你怎么知道它被替换了?
-
@Paul 是的 $Pathname 变量绝对正确。我还写入了一个日志文件,确认 filesize($Pathname) 是实际文件大小。
-
@BartFriederichs - 通过查看 Firefox (F12) 中的网络活动。
-
尝试添加 header('Dummy-Length: ' .filesize($Pathname));和 header('Dummy-Exists: ' . file_exists($Pathname));