Forum Moderators: coopster & phranque

Message Too Old, No Replies

Parsing mult-part form data

For uploading image file along with text in form

         

WriterSP

4:26 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Hello everyone,

I've got the parsing of text down to a routine, but now I've got an html form which includes the option to upload an image.

I'm stymied on how to set up the parse routine in Perl to accommodate the uploaded image file along with my text info.

Any insight into this would be greatly appreciated.

This is the typical routine I use for parsing text:

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pairs (@pairs) {
local($name, $value) = split(/=/, $pairs);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.¦\n)*-->//g;
if ($Form{$name} && $value) {
$Form{$name} = "$Form{$name}, $value";
}
elsif ($value) {
push(@Field_Order,$name);
$Form{$name} = $value;
}
}
local($key,$sort_order,$sorted_field);

foreach $field (@Field_Order) {
push(@FormData, $Form{$field});
}

bennymack

4:43 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



That looks like a really hard way to do it. I'm all about code reuse. I did a search for upload on [search.cpan.org...] and found [search.cpan.org...] that looks like it might be helpful. If you really didn't want to use it, maybe you can rip the applicable code out of it.

jatar_k

9:52 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and Welcome to WebmasterWorld WriterSP

rocknbil

1:27 am on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Writer SP - I haven't used upload.PM but I use CGI.pm for multipart parsing, that also works great. It's actually the only time I call in that module.

The deal is part of the data you are sending can be plain text and part of it is binary data. In that data there is a "separator" that defines the . . . multi-parts. :-) I dug around in cgi.pm for a while but got lost and had projects to complete, it's pretty heavy stuff.

Use the modules and save your brain for bigger tasks.

WriterSP

12:12 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Thank you everyone! I appreciate the help and advice; I've always thought that that's one of the coolest things about the internet--you can always find the information you need, somewhere from somebody.

Now I've got to get crackin' on that parsing.

Thanks again.