【发布时间】:2014-11-19 04:02:49
【问题描述】:
我使用 Apache 作为后端服务器,使用 nginx 作为前端服务器。我需要使 PDF 文件可下载(此时它们正在浏览器窗口中打开)。
这是一个链接:
<a href="http://domain.com/files/teltomat.pdf" target="">link</a>
这是我迄今为止在 .htaccess 文件中尝试过的内容:
<FilesMatch "\.(pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
没用,只是在浏览器中打开文件。
AddType application/force-download pdf
没用。
AddType application/octet-stream .pdf
没用。
更新
已尝试:wget --server-response -O /dev/null http://domain.com/files/teltomat.pdf
得到了回应:
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 24 Sep 2014 17:40:54 GMT
Content-Type: application/pdf
Content-Length: 3116445
Last-Modified: Wed, 24 Sep 2014 13:28:07 GMT
Connection: keep-alive
Keep-Alive: timeout=60
ETag: "5422c6e7-2f8d9d"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Length: 3116445 (3,0M) [application/pdf]
Saving to: ‘/dev/null’
【问题讨论】:
-
我认为这与 Laravel 没有任何关系。
-
您是否验证了标头是否已进入浏览器,例如与
wget --server-response -O /dev/null http://domain.com/files/teltomat.pdf或Windows 等效? IME,浏览器不会嗅探内容。