mlseim
02-13-2007, 07:27 PM
I had a photo upload script that worked well a week ago, but suddenly
it does not work. My webhost claims nothing has changed.
The HTML form has a spot for up to 5 photos and some text boxes.
I narrowed down the script to the part shown below, with a few
print lines to see what the variables are from the form. The
variable are now coming up null (blank).
I'm just stumped as to why this quit working. Perhaps there's a better
way to bring in multiple files with text boxes mixed together on a form?
#!/usr/bin/perl
binmode(STDIN);
&Parse_Multi;
foreach $item (keys %CGI) {
$var="$item";
$val="$CGI{$item}";
if ($var =~ /\_val/is) {
if ($val eq "") {$var=~ s#\_val##is;$var=~ s#^(.*?)\_##is;error("$var cannot be empty!");}
}
}
## I put this part in to test it out ... the variables are blank.
$direct = $CGI{direct};
$redirect_link = $CGI{'redirect_link'};
print "Content-type:text/html \n\n";
print "direct: ".$direct;
print "<br>";
print "redirect: ".$redirect_link;
print "<br>";
exit;
sub Parse_Multi {
local($boundary,@pairs,$position);
local($raw_data,$value,$name,$part);
$raw_data = &Parse_Method;
($boundary = $ENV{CONTENT_TYPE}) =~ s/^.*boundary=(.*)$/\1/;
@pairs = split(/--$boundary/, $raw_data);
@pairs = splice(@pairs,1,$#pairs-1);
for $part (@pairs) {
$part =~ s/[\r]\n$//g;
($dump, $firstline, $datas) = split(/[\r]\n/, $part, 3);
next if $firstline =~ /filename=\"\"/;
$firstline =~ s/^Content-Disposition: form-data; //;
(@columns) = split(/;\s+/, $firstline);
($name = $columns[0]) =~ s/^name="([^"]+)"$/\1/g;
if ($#columns > 0) {
if ($datas =~ /^Content-Type:/) {
($CGI{"$name"}->{'Content-Type'}, $blankline, $datas) = split(/[\r]\n/, $datas, 3);
$CGI{"$name"}->{'Content-Type'} =~ s/^Content-Type: ([^\s]+)$/\1/g;
}
else {
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
$CGI{"$name"}->{'Content-Type'} = "application/octet-stream";
}
}
else {
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
if (grep(/^$name$/, keys(%CGI))) {
if (@{$CGI{$name}} > 0) {
push(@{$CGI{$name}}, $datas);
}
else {
$arrvalue = $CGI{$name};
undef $CGI{$name};
$CGI{$name}[0] = $arrvalue;
push(@{$CGI{$name}}, $datas);
}
}
else {
next if $datas =~ /^\s*$/;
$CGI{"$name"} = $datas;
}
next;
}
for $currentColumn (@columns) {
($currentHeader, $currentValue) = $currentColumn =~ /^([^=]+)="([^"]+)"$/;
$CGI{"$name"}->{"$currentHeader"} = $currentValue;
}
$CGI{"$name"}->{'Contents'} = $datas;
}
}
it does not work. My webhost claims nothing has changed.
The HTML form has a spot for up to 5 photos and some text boxes.
I narrowed down the script to the part shown below, with a few
print lines to see what the variables are from the form. The
variable are now coming up null (blank).
I'm just stumped as to why this quit working. Perhaps there's a better
way to bring in multiple files with text boxes mixed together on a form?
#!/usr/bin/perl
binmode(STDIN);
&Parse_Multi;
foreach $item (keys %CGI) {
$var="$item";
$val="$CGI{$item}";
if ($var =~ /\_val/is) {
if ($val eq "") {$var=~ s#\_val##is;$var=~ s#^(.*?)\_##is;error("$var cannot be empty!");}
}
}
## I put this part in to test it out ... the variables are blank.
$direct = $CGI{direct};
$redirect_link = $CGI{'redirect_link'};
print "Content-type:text/html \n\n";
print "direct: ".$direct;
print "<br>";
print "redirect: ".$redirect_link;
print "<br>";
exit;
sub Parse_Multi {
local($boundary,@pairs,$position);
local($raw_data,$value,$name,$part);
$raw_data = &Parse_Method;
($boundary = $ENV{CONTENT_TYPE}) =~ s/^.*boundary=(.*)$/\1/;
@pairs = split(/--$boundary/, $raw_data);
@pairs = splice(@pairs,1,$#pairs-1);
for $part (@pairs) {
$part =~ s/[\r]\n$//g;
($dump, $firstline, $datas) = split(/[\r]\n/, $part, 3);
next if $firstline =~ /filename=\"\"/;
$firstline =~ s/^Content-Disposition: form-data; //;
(@columns) = split(/;\s+/, $firstline);
($name = $columns[0]) =~ s/^name="([^"]+)"$/\1/g;
if ($#columns > 0) {
if ($datas =~ /^Content-Type:/) {
($CGI{"$name"}->{'Content-Type'}, $blankline, $datas) = split(/[\r]\n/, $datas, 3);
$CGI{"$name"}->{'Content-Type'} =~ s/^Content-Type: ([^\s]+)$/\1/g;
}
else {
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
$CGI{"$name"}->{'Content-Type'} = "application/octet-stream";
}
}
else {
($blankline, $datas) = split(/[\r]\n/, $datas, 2);
if (grep(/^$name$/, keys(%CGI))) {
if (@{$CGI{$name}} > 0) {
push(@{$CGI{$name}}, $datas);
}
else {
$arrvalue = $CGI{$name};
undef $CGI{$name};
$CGI{$name}[0] = $arrvalue;
push(@{$CGI{$name}}, $datas);
}
}
else {
next if $datas =~ /^\s*$/;
$CGI{"$name"} = $datas;
}
next;
}
for $currentColumn (@columns) {
($currentHeader, $currentValue) = $currentColumn =~ /^([^=]+)="([^"]+)"$/;
$CGI{"$name"}->{"$currentHeader"} = $currentValue;
}
$CGI{"$name"}->{'Contents'} = $datas;
}
}