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.
| [reply] [d/l] |
Thanks for your reply ichimunki,
My major problem concerns the unicode format. I do not no how to convert it in standard text and html. I assume that I have to use the unicode module, but I am very short in time so any help is welcome.
| [reply] |
#!/usr/bin/perl -w
use strict;
use Text::Iconv;
use HTML::Entities;
# create the conversion method (only once)
my $conv = Text::Iconv->new("utf8", "latin1");
my $html_text = encode_entities( $conv->convert( $utf8_text));
If you want to get fancy you can use the bit of code in converting character encodings | [reply] [d/l] |
I figured as much, you should be more specific in the question then! :)
Unicode::String is the module I would look at. It appears to supply methods for converting unicode into a variety of more 8-bit friendly forms.
| [reply] |
As of right now there isnt suppert for unicode (as text) in mysql, do you want it stored in unicode or can it be converted to something like iso-8859-1?
T
I
M
T
O
W
T
D
I | [reply] |
Time,
Thanks for yor reply. I would like to converter special signs (for instance greek symbols, trademark, etc..) in html and the "normal" characters in "normal" text
| [reply] |
| [reply] |