浏览器下载文件而不是显示它

时间:2013-01-15 14:14:03

标签: header download http-headers readfile

我使用php readfile将文件发送到浏览器。它是一个图像文件。浏览器如何下载它,而不是显示它。 这是响应头:

HTTP/1.1 200 OK
Date: Tue, 15 Jan 2013 14:11:46 GMT
Server: Apache
X-Powered-By: PHP/5.3.18-nmm1
Content-disposition: attachment; filename=test.jpg
Content-Length: 20599
Keep-Alive: timeout=1, max=100
Connection: Keep-Alive
Content-Type: image/jpeg; charset=binary

为什么不显示?

1 个答案:

答案 0 :(得分:2)

坏人就是这句话:

Content-disposition: attachment; filename=test.jpg

尝试删除它以便在浏览器中显示图像。

或者,使用一个小的html文件,因为这是浏览器的工作方式;)

相关问题