Welcome to WebmasterWorld Guest from 54.158.237.30

Forum Moderators: incrediBILL

Message Too Old, No Replies

How do I force the download of image files?

     
10:11 pm on Jan 22, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 16, 2004
posts:61
votes: 0


when you click a link that leads to an image file
(http://www.........../image.jpg)
it opens in a new window/tab

is there a way to force the image to download as if it was a file, the download box would open up I mean?

does it have to reside in ftp or something...?

1:01 am on Jan 23, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 4, 2002
posts:1687
votes: 0


Browsers recognize jpg URL's and hand them over just like a .htm, so I don't think you can force it on the user-end (not positive on that, though). Maybe you could do it with a server-side script somehow?
10:47 am on Jan 23, 2006 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9068
votes: 4


I'm a little confused by your post, do you want a download prompt to appear and the image to be downloaded to a location on the user's hard drive, or you you want the image to open or be displayed in a pop-up window?

If the former, you can attempt to force the download of files if the server is running Apache: see this recent thread in the Apache server forum:

[webmasterworld.com...]

If it is the latter you want, you will need to use Javascript to open a new window from a link in an HTML page.

4:52 am on Jan 24, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


The problem is that browsers will "sniff out" the file, even if you change the extension, and try to manage it accordingly. To effectively force the download of a known MIME type, you need to deliver it via server side programming and "munge" the content-type header. This makes the browser force the download dialogue.

See my post in this thread [webmasterworld.com], this works.