I need to be able to have a subdirectory of images all PNG's to be downloaded instead of opened in the browser window. I am using IIS for the web server.
我需要能够下载所有PNG的图像子目录,而不是在浏览器窗口中打开。我正在使用IIS作为Web服务器。
Is there a way to force a PNG to be downloadable?
有没有办法强制PNG可下载?
5 个解决方案
#1
As the other posters have said, you need to add the HTTP Content-Disposition header, with a value of attachment, to the HTTP response generated by IIS when serving the PNGs in question.
正如其他海报所说的那样,您需要将HTTP Content-Disposition标头(附件值)添加到IIS在为相关PNG提供服务时生成的HTTP响应中。
Not sure what version of IIS you using are but:
不确定您使用的是哪个版本的IIS,但是:
IIS6
- In the IIS Manager select the directory with the PNG files and open the Properties dialog
- Click the HTTP Headers tab.
- In the Custom HTTP Headers section, click Add.
- A dialog appears. In the "Custom-header name" field enter "Content-disposition". In the "Custom-header value field, enter "Attachment".
- You may have to restart IIS (iisreset)
在IIS管理器中,选择包含PNG文件的目录,然后打开“属性”对话框
单击HTTP标头选项卡。
在“自定义HTTP标头”部分中,单击“添加”。
出现一个对话框。在“自定义标题名称”字段中,输入“内容处置”。在“自定义标题值”字段中,输入“附件”。
您可能必须重新启动IIS(iisreset)
For IIS7:
- In the IIS Manager select the directory with the PNG files and select the Features view.
- Double-click the HTTP Response Headers item and then choose the Add option in the right-hand menu.
- A dialog appears. In the "Name" field enter "Content-disposition". In the "Value" field, enter "Attachment".
- You may have to restart IIS (iisreset)
在IIS管理器中,选择包含PNG文件的目录,然后选择“功能”视图。
双击HTTP Response Headers项,然后在右侧菜单中选择Add选项。
出现一个对话框。在“名称”字段中输入“内容处置”。在“值”字段中,输入“附件”。
您可能必须重新启动IIS(iisreset)
Alternatively, place this web.config in the folder with files:
或者,将此web.config放在包含文件的文件夹中:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="Content-Disposition" value="Attachment" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
This should force the PNGs served from that directory to be downloadable.
这应该强制可以下载从该目录提供的PNG。
#2
You can't if you directly serve the PNGs, but if you use ASP, you can add:
如果直接提供PNG,则不能,但如果使用ASP,则可以添加:
Response.AddHeader("Content-Disposition", "attachment");
#3
You have to send this header to the browser:
您必须将此标头发送到浏览器:
Content-Disposition:attachment; filename="downloaded.pdf"
I have no clue on how to do this using IIS.
我不知道如何使用IIS来做到这一点。
#4
All solutions I have tried make it so that it'll download in other browsers except IE. IE is trying to be "helpful" and decides what it thinks would best server the client, in this case is display the png file in the browser.
我尝试过的所有解决方案都可以在IE以外的其他浏览器中下载。 IE正在尝试“有用”并决定它认为最好服务于客户端的内容,在这种情况下是在浏览器中显示png文件。
There is always the programatic way of doing this as been pointed out. But I wasn't looking to go that route.
正如所指出的那样,总是有编程方式。但我不打算走那条路。
In the end I individually zipped up the 67 PNG files and linked to those. It's not pretty but it works.
最后,我单独压缩了67个PNG文件并链接到那些文件。它不漂亮,但它的工作原理。
Thanks all for the help.
谢谢大家的帮助。
#5
Probably, my answer is outdated but hopefully it can be useful for someone...
可能,我的答案已经过时,但希望它对某些人有用......
As the other posters have said, you need to add the HTTP 'Content-Disposition' response header.
正如其他海报所说,你需要添加HTTP'Content-Disposition'响应头。
The problem could appear if you can't use IIS Manager and have to use command line.
如果您不能使用IIS管理器并且必须使用命令行,则可能会出现此问题。
So, if you need to add this pretty HTTP response header using command line only, you can use such construction:
因此,如果您只需要使用命令行添加这个漂亮的HTTP响应头,则可以使用这样的构造:
%systemroot%\system32\inetsrv\APPCMD set config "Default Web Site/path/to/images" /section:httpProtocol /+customHeaders.[name='Content-disposition',value='Attachment']
It will add HTTP 'Content-Disposition' response header for your '/path/to/images' folder of your 'Default Web Site'.
它将为“默认网站”的“/ path / to / images”文件夹添加HTTP“Content-Disposition”响应标头。
This can be useful in case you do autimaticaly configuration of your IIS with a couple of scripts or BAT/CMD-files.
如果您使用几个脚本或BAT / CMD文件进行IIS的autimaticaly配置,这将非常有用。
#1
As the other posters have said, you need to add the HTTP Content-Disposition header, with a value of attachment, to the HTTP response generated by IIS when serving the PNGs in question.
正如其他海报所说的那样,您需要将HTTP Content-Disposition标头(附件值)添加到IIS在为相关PNG提供服务时生成的HTTP响应中。
Not sure what version of IIS you using are but:
不确定您使用的是哪个版本的IIS,但是:
IIS6
- In the IIS Manager select the directory with the PNG files and open the Properties dialog
- Click the HTTP Headers tab.
- In the Custom HTTP Headers section, click Add.
- A dialog appears. In the "Custom-header name" field enter "Content-disposition". In the "Custom-header value field, enter "Attachment".
- You may have to restart IIS (iisreset)
在IIS管理器中,选择包含PNG文件的目录,然后打开“属性”对话框
单击HTTP标头选项卡。
在“自定义HTTP标头”部分中,单击“添加”。
出现一个对话框。在“自定义标题名称”字段中,输入“内容处置”。在“自定义标题值”字段中,输入“附件”。
您可能必须重新启动IIS(iisreset)
For IIS7:
- In the IIS Manager select the directory with the PNG files and select the Features view.
- Double-click the HTTP Response Headers item and then choose the Add option in the right-hand menu.
- A dialog appears. In the "Name" field enter "Content-disposition". In the "Value" field, enter "Attachment".
- You may have to restart IIS (iisreset)
在IIS管理器中,选择包含PNG文件的目录,然后选择“功能”视图。
双击HTTP Response Headers项,然后在右侧菜单中选择Add选项。
出现一个对话框。在“名称”字段中输入“内容处置”。在“值”字段中,输入“附件”。
您可能必须重新启动IIS(iisreset)
Alternatively, place this web.config in the folder with files:
或者,将此web.config放在包含文件的文件夹中:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="Content-Disposition" value="Attachment" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
This should force the PNGs served from that directory to be downloadable.
这应该强制可以下载从该目录提供的PNG。
#2
You can't if you directly serve the PNGs, but if you use ASP, you can add:
如果直接提供PNG,则不能,但如果使用ASP,则可以添加:
Response.AddHeader("Content-Disposition", "attachment");
#3
You have to send this header to the browser:
您必须将此标头发送到浏览器:
Content-Disposition:attachment; filename="downloaded.pdf"
I have no clue on how to do this using IIS.
我不知道如何使用IIS来做到这一点。
#4
All solutions I have tried make it so that it'll download in other browsers except IE. IE is trying to be "helpful" and decides what it thinks would best server the client, in this case is display the png file in the browser.
我尝试过的所有解决方案都可以在IE以外的其他浏览器中下载。 IE正在尝试“有用”并决定它认为最好服务于客户端的内容,在这种情况下是在浏览器中显示png文件。
There is always the programatic way of doing this as been pointed out. But I wasn't looking to go that route.
正如所指出的那样,总是有编程方式。但我不打算走那条路。
In the end I individually zipped up the 67 PNG files and linked to those. It's not pretty but it works.
最后,我单独压缩了67个PNG文件并链接到那些文件。它不漂亮,但它的工作原理。
Thanks all for the help.
谢谢大家的帮助。
#5
Probably, my answer is outdated but hopefully it can be useful for someone...
可能,我的答案已经过时,但希望它对某些人有用......
As the other posters have said, you need to add the HTTP 'Content-Disposition' response header.
正如其他海报所说,你需要添加HTTP'Content-Disposition'响应头。
The problem could appear if you can't use IIS Manager and have to use command line.
如果您不能使用IIS管理器并且必须使用命令行,则可能会出现此问题。
So, if you need to add this pretty HTTP response header using command line only, you can use such construction:
因此,如果您只需要使用命令行添加这个漂亮的HTTP响应头,则可以使用这样的构造:
%systemroot%\system32\inetsrv\APPCMD set config "Default Web Site/path/to/images" /section:httpProtocol /+customHeaders.[name='Content-disposition',value='Attachment']
It will add HTTP 'Content-Disposition' response header for your '/path/to/images' folder of your 'Default Web Site'.
它将为“默认网站”的“/ path / to / images”文件夹添加HTTP“Content-Disposition”响应标头。
This can be useful in case you do autimaticaly configuration of your IIS with a couple of scripts or BAT/CMD-files.
如果您使用几个脚本或BAT / CMD文件进行IIS的autimaticaly配置,这将非常有用。