> I am writing a program that needs to process form data, (here's
>   the kicker) which is sometimes multipart/form-data, then
>   redirect a user to a GET request (which doesn't need to process
>   the form data).  I would like to use the standard mechanism for
>   issuing a redirect, for other reasons:
>
>           $r->header_out('Location' => $url);
>           return REDIRECT;
>

Not sure what the problem is, but I frequently use REDIRECTs and receive both
"normal" and "multipart" posts.

Please find the code section below that I use to get the POSTed data. After
that, in order to REDIRECT, I use

              $r->content_type('text/html');
               $r->header_out(Location =>
'http://'.$ENV{'HTTP_HOST'}.$disurl);
               return REDIRECT;

Hope this helps.

Enjoy,

- Gerd.

============ Getting all kind of posted stuff:

        my $buffer;

        $r->read($buffer,$r->header_in('Content-length'));

        unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si)
{
            my @pairs=split(/&/,$buffer);
            my $pair;
            foreach $pair (@pairs) {
               my ($name,$value) = split(/=/,$pair);
               $value =~ tr/+/ /;
               $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
               $name  =~ tr/+/ /;
               $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
               $ENV{"form.$name"}=$value;
            }
        } else {
            my $contentsep=$1;
            my @lines = split (/\n/,$buffer);
            my $name='';
            my $value='';
            my $fname='';
            my $fmime='';
            my $i;
            for ($i=0;$i<=$#lines;$i++) {
                if ($lines[$i]=~/^$contentsep/) {
                    if ($name) {
                        chomp($value);
                        if ($fname) {
                            $ENV{"form.$name.filename"}=$fname;
                            $ENV{"form.$name.mimetype"}=$fmime;
                        } else {
                            $value=~s/\s+$//s;
                        }
                        $ENV{"form.$name"}=$value;
                    }
                    if ($i<$#lines) {
                        $i++;
                        $lines[$i]=~

/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
                        $name=$1;
                        $value='';
                        if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
                           $fname=$1;
                           if
                            ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {

                              $fmime=$1;
                              $i++;
                           } else {
                              $fmime='';
                           }
                        } else {
                            $fname='';
                            $fmime='';
                        }
                        $i++;
                    }
                } else {
                    $value.=$lines[$i]."\n";
                }
            }
        }
            $r->method_number(M_GET);
            $r->method('GET');
            $r->headers_in->unset('Content-length');



>
begin:vcard 
n:Kortemeyer;Gerd
tel;fax:(517) 432-2175
tel;work:(517) 432-5468
x-mozilla-html:FALSE
url:http://www.lite.msu.edu/kortemeyer/
org:LITE Lab;DSME MSU
version:2.1
email;internet:[EMAIL PROTECTED]
title:Instructional Technology Specialist
adr;quoted-printable:;;123 North Kedzie Labs=0D=0AMichigan State University;East Lansing;MI;48824;USA
fn:Gerd Kortemeyer
end:vcard

Reply via email to