如何使用 php.ini / httpd.conf / .htaccess 设置 Content-Length header?

How to set Content-Length header with php.ini / httpd.conf / .htaccess?

我的 bluehost 共享托管服务器上有一些 pdf 文件。我需要从 iOS 应用程序下载它们并且我想显示下载进度条。

但我不能,因为 Content-length 不存在于 Header 响应中。

我怎样才能得到这个?

您可以通过header设置。使用 header 函数可以设置 HTTP 信息。但请注意,在设置 HTTP 信息之前,您没有任何输出。

header('Content-type: application/pdf');
header("Content-length: $size");
header('Content-Disposition: attachment; filename="downloaded.pdf"');

编辑:

如果您不使用 PHP 下载文件,您可以在 htaccess 中使用 SetEnv no-gzip dont-vary 来禁止 GZIP。