1
後下載我下載的是通過PHP腳本位於服務器上(文件可以打開)PDF文件:gzip壓縮的文件通過PHP
ini_set("zlib.output_compression", "Off"); // just to be sure
$quoted = sprintf('"%s"', addcslashes(basename($fileName), '"\\'));
$size = filesize($fileName); // size at this stage is correct
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
ob_clean();
flush();
readfile($fileName);
ini_set("zlib.output_compression", "On");
exit;
下載的文件是gzip壓縮。尺寸比原來小。只有在最後添加.gz擴展名並提取文件後才能打開該文件。
服務器API CGI/FastCGI的
PHP 7.1.0版本
lighttpd的1.4.35
請求頭
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:en-US,en;q=0.8
Authorization:Basic ************
Cache-Control:max-age=0
Connection:keep-alive
Host:dev.*********.lv
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
響應頭
Cache-Control:must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Description:File Transfer
Content-Disposition:attachment; filename="INV_AUC15-3_U1_DDDDD-IIII_03112016.pdf"
Content-Length:831807
Content-Transfer-Encoding:binary
Content-Type:application/octet-stream
Date:Wed, 04 Jan 2017 10:22:19 GMT
Expires:0
Last-Modified:Wed, 04 Jan 2017 10:22:19 GMT
Pragma:public
Server:FS
X-Powered-By:PHP/7.1.0
Content-Length標頭是正確的(與文件系統上的相同)。
如果我把完整的URL指向PDF文件,該文件被下載並打開時沒有任何問題。
爲什麼或什麼時候目標文件在被下載之後/之前默默地gzip?!
測試在Chrome,火狐,Safari,歌劇