sub DownloadFile { my $id = shift; $sth = $dbh->prepare(qq{ select name,data from foo where id = ? and type = 'file' }) or Errors("Could not prepare SQL for file $id: $DBI::errstr"); $rc = $sth->execute($id) or Errors("Could not execute SQL for file $id: $DBI::errstr"); my ($name,$data) = $sth->fetchrow_array(); my $size = length($data); print "Content-disposition: inline; filename=$name\n"; print "Content-Length: $size\n"; print "Content-Type: application/octet-stream\n\n"; print $data; return(1); }