On 2004.8.22, at 04:07 AM, Chris Devers wrote:
On Sat, 21 Aug 2004, Mark Wheeler wrote:
I have a picture gallery I building for my family. When a movie or picture is displayed, I want them to be able to save it. But... if I just provide a link in the coding to the actual file, it will open up in the browser window and be displayed. Is there a way to have download, either automatically or by a "Save As..." dialog box, the file rather then displaying it? I hope that was clear. :)
This is untested, but I'm guessing that you could write a simple CGI script that takes the URL for an image as an argument -- maybe just using $ENV{'HTTP_QUERY_STRING'} so that the url can be simple like --
http://site/images/fetch.pl?path/to/image/file.jpg
-- and then have your script find "path/to/image/file.jpg" and spool it back to the client with a Content-type of "application/octet-stream" instead of "image/jpeg".
This can probably be done with about half a dozen lines of code, and if the browser is well behaved -- that'll be the part that's a pain to verify -- the alternate content type should force the right behavior.
Worked on a project where we wanted pdfs to automatically open in Adobe Acrobat. Various things we tried worked with some browsers and not with others, and I had to point out that some people would have their browsers set to save everything to disk. Boss decided that anyone who knew enough to set the browser to save everything to disk would be assumed to be unlikely to be surprised at the results.
You should have less problems because the save-to-disk is what you're going after, but some browsers in some settings will attempt an ascii dump to the browser.
I have a script that builds a page that spreads a set of pictures out in a table with links to several resolutions (no, not filtering the resolution at run-time). I did not bother with setting the Content-type in the download links because I knew two things -- those relatives who would not know to right-click would also not know what to do with the files when downloaded, and I was pretty sure the one person I wanted to be able to download would not have to be told to right-click or control-click.
Sorry to say, I won that bet with myself, so I didn't bother building in the Content-type machinery which is most interesting in this thread. If anyone's interested in what I did put together, I could post it.
--
Joel Rees
Complaining about systems that are incomplete misses the point.
In this world, a system can't be perfect and useful at the same time.
Of course, there's no excuse for refusing to fix problems --
we'll never run out of problems.