#! /usr/bin/perl -wT use strict; #force all variables to be declared before use use DBI; # import database interface methods use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use lib qw(/home/gmacfadd/public_html/cgi-bin/WorkControl); use WorkControlDB; print header (), # use the text/html (default) Content-type headet start_html (); my $dbh = WorkControlDB::connect (); my ($sth, $stmt, $row, $blob_field); $stmt = qq { SELECT * FROM testblob WHERE id = ?}; $sth = $dbh->prepare ($stmt); # tell DBI what we are doing via prepare method $sth->execute ("1"); # search for record with id = given number $row = $sth->fetchrow_hashref(); $sth->finish (); # close the DBI result set $blob_field = $row->{file}; # .. get data from blob into $blob_field. print "Content-type: $row->{mime_type}\n"; # use content-type for the field print "Content-disposition: attachment; filename=somefile.bmp\n\n"; binmode STDOUT; print $blob_field; print end_html (); exit (0);