Microsoft
Software
Hardware
Network
Question : robust upload file without CGI.pm
Hi,
Im trying to make a perl-CGI upload script without the CGI.pm module. I know its easier but I want to understand several things. First my upload.html has several fields (and a file input box) and submits via ENCTYPE="multipart/form-da
ta", so when my CGI grabs it all (from POST) via STDIN, I get some strings like:
--------------------------
---7d61b51
b10426
Content-Disposition: form-data; name="email_address"
[email protected]
--------------------------
---7d61b51
b10426
Content-Disposition: form-data; name="Submit"
Submit Form
--------------------------
---7d61b51
b10426--
I was wondering if anyone has a quick way to parse this? Maybe turn it into hashes or something? Also in this is the binary content of the file I uploaded, so Im also trying to not only get field values, but also upload a file (without the CGI module).
Thanks.
Answer : robust upload file without CGI.pm
I'm going to wash my hands after posting this. This is a crude way of parsing the from data into a hash:
my %IN = read_parse();
sub read_parse {
my $buffer;
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {die "Invalid request method";}
my @pairs = split(/&/, $buffer);
foreach (@pairs) {
my($name, $value) = split(/=/, $_);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9]{2})/pack("
c", hex($1))/eg;
if (defined($IN{$name})){$IN{
$name} .= "\0";}
$IN{$name} .= $value;
}
return %IN;
}
the above is not recommended but it might give you some insight.
Random Solutions
Interactive Sorting with drill-down groups collapses group when sorting
DBase IV and Unexpected Error
my laptop refuse connecting to my flash card
Emprex camera DSC3380S to work under Linux FC4, possible?
Access Query - how to manipulate date in format yyyymm
need a step by step on how to setup Reverse DNS for Exchange mail server.
Need information on Long Integer, Integer, Byte, Single, Double, Replication ID, etc.
Link a Query to a From
Multiple AJAX calls / request at Ruby on Rails
SMTP Open Relay Authentication