### Parse a multipart form (dump regular variables into standard form constructs
### and store files separately)
###
sub parse_multipart {
my ($clength) = @_;
$clength = $ENV{'CONTENT_LENGTH'} if $clength == 0;
undef my $output;
my $type = $ENV{'CONTENT_TYPE'}; my $boundary = ""; my $len = 0;
my $input = ""; my $counter = 0;
binmode(STDIN);
if ($type =~ /boundary=(.*)/) {
$boundary = join("--" , $1);
} else {
error_message("Upload Error", "Your browser did not properly encode this form.", 0, 1);
}
while ($len < $clength) {
my $buf = "";
$len += sysread(STDIN, $buf, $clength);
$input .= $buf;
$counter += 1;
$counter = 0 if $buf ne "";
error_message("Upload Error", "The upload timed out after reading $len of $clength bytes. Please try again by hitting your browser's RELOAD button.", 0, 1) if $counter >= 100;
}
my @input_pairs = split(/$boundary/, $input);
my $formname = "";
my $filename = "";
foreach my $line (@input_pairs) {
my ($header, $body) = split(/\r\n\r\n|\n\n/, $line, 2);
$u = $GLOBAL_OPTIONS->{'public_maxsize'} * 1000 if $author_status < 3;
return 0 if $u == 0;
return 0 if $filesize < $u;
return sprintf("%.1f", $u/1000);
}
###
### post_save_uploaded_attachment
###
### Saves an uploaded attachment in a temporary directory
###
sub post_save_uploaded_attachment {
my ($attachment_info, $content_type, $fi, $tempfile, $descr, $ct) = @_;
my $res = post_format_attachment_file($attachment_info, $content_type, $fi, $descr, $ct);
my $d = (defined $res->{data} ? $res->{data} : $attachment_info->{data});
if (! -d "$DCONF->{admin_dir}/msg_index/uploads") {
mkdir("$DCONF->{admin_dir}/msg_index/uploads", oct($DCONF->{perms0777})) || error_message("Create Directory Error", "Could not create 'uploads' directory under 'msg_index'. Post with image/attachments failed.");