in reply to downloading files from mySQL

Your post is pretty hard to read. Please read writeup formatting tips.

Anyway, here's a reasonable start:

# .. get data from blob into $blob_field. print "Content-type: application/octet-stream\n"; # or use the right c +ontent-type for the field if you know it print "Content-disposition: attachment; filename=somefile.ext\n\n"; binmode STDOUT; print $blob_field;
I have no idea what LWP has to do with any of this, though.

update: ah it appears you want a "file-download field" in your form. There is no such thing as such in HTML. My code above will work fine if you link to it though - it will (or rather, should) cause the browser to open a "save as..." file selector and save the content to that file. You can only send one file per request this way, so your best bet is to create a list of links for each blob field. In other words, the script above should be called as a CGI for each field.

Replies are listed 'Best First'.
Re^2: downloading files from mySQL
by gmacfadden (Sexton) on Nov 01, 2006 at 18:36 UTC
    Very helpful, thank you.
Re^2: downloading files from mySQL
by gmacfadden (Sexton) on Nov 03, 2006 at 19:53 UTC
    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);