Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing html form with enctype="multipart/form-data"

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I was wondering what is needed to parse the incoming data when it is sent with the multipart/form-data enctype.

I have tried parsing the <STDIN>, but to no avail. I would like to stay away from using the CGI.pm because when I parse it, there are a number of things that I want to do.

any ideas?

Robert Carpenter
/b{2}|!b{2}/ - that is the question...
robert@convertingchaos.com
 
Try this. Not sure it would work without CGI.pm, but it does the trick.

Code:
my $filename = param('file');

my $file = (split/\\/, $filename)[-1];

$file = lc(join '', (split / /, $file));

my ($total_size, $size, $data);

open(SAVE, ">$outputdir/$file") or die "Can't open file: $!";

binmode SAVE;

while($size = read(param('file), $data, 1024))
{
    print SAVE $data;
    $total_size += $size;
}

close(SAVE);
 
For added control you can read the Content-length header and only read that much data.
 
yea, the troblesome part is the param(...) part. I think that is reliant on the cgi mod.

The biggest hurdle that I am trying to leap is just parsing information from the form under that encoding.

Robert Carpenter
/b{2}|!b{2}/ - that is the question...
robert@convertingchaos.com
 
Well, multipart/form-data usually means that you have some value pairs. If your just reading a file off a stream I don't think that is the appropriate encoding?

Good luck, feels like your doing it the hard way but I do not have enough info on your implementation to prove it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top