in reply to Re: downloading files from mySQL
in thread downloading files from mySQL
#! /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 WorkCo +ntrolDB; 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 prep +are 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_fie +ld. 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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: downloading files from mySQL
by Joost (Canon) on Nov 05, 2006 at 14:59 UTC |