Perl Problem with enctype="multipart/form-data"
by "R K Williams" <richard.williams(at)datadata.net>
|
| Date: |
Mon, 20 Mar 2000 11:50:21 -0000 |
| To: |
<hwg-languages(at)hwg.org> |
| |
todo: View
Thread,
Original
|
|
Hi
I would like to use a form to attach files to an email to be sent via a
perl script - the form is not the problem, the script is. Also, my hosting
service assures me enctype="multipart/form-data" is part of their default
settings.
For the record in the form I have put...
<FORM action="../cgi-bin/whatever.pl" method="post"
enctype="multipart/form-data">
<!-- LOAD OF OTHER FORM TYPE STUFF -->
<INPUT type="file" name="file_attached" size="35">
<!-- etc etc -->
</FORM>
In the perl script, right at the very end, but before...
EOF
close(MAIL);
exit;
I've put...
File attached: $form{'file_attached'}
Does anyone know how to modify the perl script below to acheive my aim or
of a free perl script that can do the job?
Thanks
Richard
=================================================
#!/usr/bin/perl
$mailprog = "/usr/lib/sendmail";
#
# Get the date
#
@days =
('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
@months =
('January','February','March','April','May','June','July','August','Septemb
r','October','November','December');
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$year = 100;
$year = $year + 1900;
$date = "$days[$wday], $months[$mon] $mday, $year at $hour\:$min\:$sec";
print "Content-type: text/html", "\n\n";
#
# If the data is not posted using the POST method, report the error
#
if ($ENV{'REQUEST_METHOD'} ne 'POST')
{
print <<EOF;
<HTML>
<HEAD>
<TITLE>ERROR</TITLE>
</HEAD>
<BODY bgcolor="#ff0000" text="#ffffff">
<H1>Incorrect data transport method used</H1>
<P>
Please report this error to the <A
href="mailto:richard.williams\(at)datadata.net">web administrator</A>
</BODY>
EOF
exit;
}
#
# Read in the name value pairs
#
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
#
# Split name value pairs and place in FORM array for use
#
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$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/<!--(.|\r\n\r\n)*-->//g;
$form{$name} = $value;
}
#
# Return web page to say Thank You
#
print <<EOF;
<HTML>
<HEAD>
<TITLE>
Whatever
</TITLE>
</HEAD>
<BODY bgcolor="#ffffff" text="#000000">
<TABLE width="100%" border="0" cellspacing="0" cellpadding="5">
<TR>
<TD align="center" valign="middle">
<H1>THANK YOU</H1>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
EOF
open(MAIL, "|$mailprog -n -oi -t") or die("Can't open $mailprog!\n");
print MAIL "To: anyone\(at)nobody.com\n";
print MAIL "From: $form{'email'} ($form{'name'})\n";
print MAIL "Subject: Whatever\n\n";
print MAIL <<EOF;
DATE SENT: $date
Full Name: $form{'name'}
Position: $form{'position'}
Nature of Business: $form{'nob'}
Legal Entity: $form{'legalentity'}
Co.Reg.No.: $form{'coregno'}
Organisation Name: $form{'bizname'}
Address 1: $form{'address1'}
Address 2: $form{'address2'}
Town/City: $form{'town'}
County: $form{'county'}
Postcode: $form{'postcode'}
Tel: $form{'tel'}
Fax: $form{'fax'}
E-Mail: $form{'email'}
File Attached: $form{'file_attached'}
EOF
close(MAIL);
exit;
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA