Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: insert file into mysql

by Adrade (Pilgrim)
on Feb 01, 2006 at 05:04 UTC ( [id://526963]=note: print w/replies, xml ) Need Help??


in reply to insert file into mysql

I think you're looking to collect a piece of textual information in addition to binary data from a file. The first thing you're gonna need to be sure of is that your table is setup correctly. Presumably, you're going to need a sort of TEXT field for the address, and you're gonna need a BLOB for the binary data.

The HTML is gonna need to be setup something like this:
<form action="http://www.site.com/path/to/script.pl" method=POST ENCTY +PE="multipart/form-data"> Address: <input type="text" name="address"><br> File: <input type="file" name="file"><br> <input type="submit"></form>
The Perl code is going to probably be something like this:
#!/usr/bin/perl use strict; use CGI; use DBI; my $cgi = new CGI; my $dbh = DBI->connect("DBI:mysql:dbname:localhost","username","passwo +rd"); my $fh = $cgi->upload('file'); my $data; $data .= $_ while <$fh>; my $p = $dbh->prepare("insert into `tablename` (`address`,`data`) valu +es (?,?)"); $p->execute($cgi->param('address'), $data); $p->finish; $dbh->disconnect;
Although this is rather basic (and untested!!), I hope it leads to an eventual solution to your problem, of course, assuming that I am understanding it correctly :-).

Best, and good luck!
  -Adam

--
By a scallop's forelocks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://526963]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found