Hi Andy (another andy),
I tried your changes, but not go. On a PC, a 0k file is saved. On a Mac, the browser (Safari 1.2.2) gives me a blank screen with nothing d/l or a save dialog box - nothing. Any ideas?
Thanks,
Mark
On Aug 24, 2004, at 4:10 PM, Andy Turner wrote:
I would also recommend using PATH_INFO instead of a query string. This will
more reliably set the filename then the content disposition will.
The HTML would be:
<html>
<head>
<title>Untitled Page</title>
</head>
<body>
<a href="javascript:window.location='cgi-bin/download.cgi/Upload- Background.gif'">picture link</a>
</body>
</html>
I would agree that slurping the entire file is a bad idea. However you don't need to use read. You can do it by setting $/ (the INPUT_RECORD_SEPARATOR) to whatever block size you want.
The result looks like this:
#!/usr/bin/perl -w use strict;
my $filename = $ENV{'PATH_INFO'}; my $path = "/images/$filename"; my $length = (stat($path))[7]; # the size, in bytes binmode STDOUT;
print "Content-Length: $size\n"; print "Content-Disposition: attachment;filename=$filename\n"; print "Content-Type: application/octet-stream\n\n";
open (FILE, "< $path") || die("Can't open($filename): $!"); binmode(FILE);
# Use 4k blocks $/ = \4_096; print while <FILE>; close (FILE);
exit;
-- Andy <[EMAIL PROTECTED]>