0
我使用Apache作为后端服务器和nginx作为前端服务器。我需要下载PDF文件(此时它们在浏览器窗口中打开)。使用htaccess强制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
没有工作。
UPDATE
尝试: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有任何关系。 – will 2014-09-24 15:34:29
您是否验证了标题可以将其传送到浏览器,例如:用'wget --server-response -O/dev/null http:// domain.com/files/teltomat.pdf'或者Windows的等价物? IME,浏览器不会内容嗅探。 – 2014-09-24 15:54:26
更新了我的答案。 – Heihachi 2014-09-24 17:43:01