the following code is incomplete, I expect you will have to read a few perldocs for the CGI and DBI and DBD::mysql modules to fill it in and make sure everything is how it should be:
#/usr/bin/perl -w
use strict;
use CGI;
use DBI;
#start our CGI object up
my $Q = CGI->new();
#we probably want to set $CGI::POST_MAX, too.
#initialize a DB handle
my $dsn = 'username:host:password'; #see perldocs for exact form
my $DBH = DBI->new( $dsn );
#check for a file
my $file = $Q->param( 'uploaded_file' );
unless ( $file )
{
#there is no file upload, so here's the form to do the upload
print $Q->header(), $Q->start_html(), $Q->start_form();
print $Q->filefield( -name => 'uploaded_file' );
print $Q->end_html();
exit;
}
my $text = join( '', <$filename> ); #slurp the whole file up
$DBH->do("INSERT INTO table VALUES( '$text' )"); #assumes blob or unic
+ode text field in target table
#status back to user
print $Q->header(), $Q->start_hmtl, $Q->p( 'Done' ), $Q->end_html;
Update: as to the unicode format issue, you can probably convert that stuff to HTML entities before you insert it, otherwise you might look at the blob field type (not ideal, but might work), after all, on some level it's just data.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.