Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force PNG to download instead of opening in browser with IIS

Tags:

iis

png

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.

Is there a way to force a PNG to be downloadable?

like image 755
RedWolves Avatar asked Jun 24 '09 19:06

RedWolves


4 Answers

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.

Not sure what version of IIS you using are but:

IIS6

  1. In the IIS Manager select the directory with the PNG files and open the Properties dialog
  2. Click the HTTP Headers tab.
  3. In the Custom HTTP Headers section, click Add.
  4. A dialog appears. In the "Custom-header name" field enter "Content-disposition". In the "Custom-header value field, enter "Attachment".
  5. You may have to restart IIS (iisreset)

For IIS7:

  1. In the IIS Manager select the directory with the PNG files and select the Features view.
  2. Double-click the HTTP Response Headers item and then choose the Add option in the right-hand menu.
  3. A dialog appears. In the "Name" field enter "Content-disposition". In the "Value" field, enter "Attachment".
  4. You may have to restart IIS (iisreset)

Alternatively, place this web.config in the folder with files:

<?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.

like image 81
Amal Sirisena Avatar answered Oct 23 '22 00:10

Amal Sirisena


You can't if you directly serve the PNGs, but if you use ASP, you can add:

Response.AddHeader("Content-Disposition", "attachment");
like image 42
MiffTheFox Avatar answered Oct 22 '22 23:10

MiffTheFox


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.

like image 33
Georg Schölly Avatar answered Oct 23 '22 01:10

Georg Schölly


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.

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.

Thanks all for the help.

like image 1
RedWolves Avatar answered Oct 23 '22 00:10

RedWolves