View Full Version : Download .jpg (not open it)

06-28-2006, 06:58 AM
I have some pictures on my website and I dont want people to right click it and do "Save picture as...". I would like to make, so that when people click on some picture it asks for download. I know this can be done in PHP, but is it possible in javascript/html...?

06-28-2006, 07:18 AM
You can set the header to "application/force-download" to do just this, but it is ignored by IE which will likely represent something like 40-70% of your viewers, depending on the type of site.

IE doesn't stick the standards.. so... that's just annoying.

The way you would do it in PHP is by setting the header... that's actually part of the download (the php page acts as the image.... outputs it directly).
Since you can't place html/javascript in a .jpg, obviously, they won't do much.
You might be able to do something to the link; i'm not sure.
Additionally, html and javascript cannot directly access the header, because it describes the page the html/js is on and must be sent before the data on the page (source code), so they couldn't do much.
You can use <meta http-equiv="..."> tags do mimic some behaviours of the headers, but I don't think that will be relavent to this issue.

.htaccess may be able to help as well.

Anyway... IE will be annoying. It'll work in other browsers, though.

The only sure way, if you really need it, is to put it in a zip file.