[WEB4LIB] Downloading gif and jpg files other than "save as"

Thomas Dowling tdowling at ohiolink.edu
Thu Jan 13 09:45:37 EST 2000


> I am setting up pages of useful logos so that staff can recognise
support from other organisations with the correct logo.
> I would like to have the logo image linked to a download of the gif or
jpg file.
> Is there any coding that would enable a download rather than opening the
files?
>
> I know you can "save as" using Netsacape.
>
> Is there an alternative such as the method used to display HTML code on
screen without it being active.


What's wrong with Save As?  It's built into the browser for a
reason--users get a consistent way to do this for any image on the web,
and don't have to learn something specific for your site (also, your
server won't have to send the image out twice, but it's your bandwidth).
For the same reason, there's a View Source command built in, so that they
can see *any* page's source, not just the ones you've treated as you
mention above.

With a little work and either a CGI script or [possibly] some clever
server configuration, you can do this.  It does not involve HTML, but
rather HTTP and MIME headers, you have to send a little white lie about
the file type, and it probably won't work in IE.  Here's a Perl CGI script
that will do it:


#!/usr/bin/perl
$file = "/path/to/directory/with/the/image.jpg";

print "Content-type: application/octet-stream
Content-Disposition: attachment; filename=foobar.jpg
Content-Description: downloaded image courtesy of Yrs Trly\n\n";

open (FILE, "$file");
binmode (FILE);
while (<FILE>) {
  print;
}



=====================
Thomas Dowling
OhioLINK - Ohio Library and Information Network
tdowling at ohiolink.edu





More information about the Web4lib mailing list