logo       

Re: Download images/movies: msg#00096

Subject: Re: Download images/movies
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 <turner@xxxxxxxxxx>





<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe