in reply to Re: downloading files from mySQL
in thread downloading files from mySQL

I implemented the solution proposed by Joost (q.v. my code below) and while it works, it's behavior is not what I extpected!

When I run this program, in lieu of fetching the file and saving the file on my computer hard drive (where it could later be opened by the proper applications), my below program dumps the binary file to my browser screen where it shows as gobble-gook.

I've worked to clean up the readability from before. Now I'm hopeful someone can please tell me how to tweek the below code to save the fetched file into a file in a Windows My Documents directory or some other directory? Thank you Monks.

#! /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