Printer Friendly Version
Email this thread to a friend
|
Featured Web Site Template |
|
Reflects user activity within the last 5 minutes
|
|
| Member |
Message |
dubz45
Joined: Feb 23, 2004
# Posts: 21
|
Posted: 2004-May-07 21:19
Hi,
I created a form on my site that allows users to type in text data such as name, address, phone, etc and upload a picture. The problem I'm having is creating a script that will retrieve the text data along with the file upload and then send it to me via email with an image attachment. The file upload part is what's really getting me. I can get the text sent just no file. Any ideas. This is keeping me up all night.
My server uses Unix and the updated Perl software.
Here's my form and script:
<CENTER><FORM name='listing' action='/cgi-bin/listing.pl' method='POST' ENCTYPE='multipart/form-data'>
<TABLE border="0" cellpadding="2" cellspacing="2" >
<TR>
<TD>
Name:
</TD>
<TD>
<INPUT type='text' name='name' size='15' value=''>
</TD>
</TR>
<TR>
<TD>
Address:
</TD>
<TD>
<INPUT type='text' name='address' size='15' value=''>
</TD>
</TR>
<TR>
<TD>
City:
</TD>
<TD>
<INPUT type='text' name='city' size='15' value=''>
</TD>
</TR>
<TR>
<TD>
Zip:
</TD>
<TD>
<INPUT type='text' name='zip' size='10' value=''>
</TD>
</TR>
<TR>
<TD>
Telephone:
</TD>
<TD>
<INPUT type='text' name='telephone' size='10' value=''>
</TD>
</TR>
<TR>
<TD>
Email:
</TD>
<TD>
<INPUT type='text' name='email' size='15' value=''>
</TD>
</TR>
<TR>
<TD>
Asking Price:
</TD>
<TD>
<INPUT type='text' name='price' size='15' value=''>
</TD>
</TR>
<TR>
<TD>
Features:
</TD>
<TD>
<TEXTAREA name='features' rows='5' cols='25'></TEXTAREA>
</TD>
</TR>
<TR>
<TD>
Details:
</TD>
<TD>
<TEXTAREA name='details' rows='5' cols='25'></TEXTAREA>
</TD>
</TR>
<TR>
<TD>
Upload Picture:
</TD>
<TD>
<INPUT type='file' name='upload' size='15'>
</TD>
</TR>
<TR>
<TD>
</TD>
<TD>
<INPUT type='checkbox' name='check' value='' >
</TD>
</TR>
<TR>
<TD>
</TD>
<TD>
<INPUT type='submit' name='submit' value='Submit Property:'>
</TD>
</TR>
</TABLE>
</FORM></CENTER>
HERE'MY SCRIPT:
#!/usr/bin/perl
$mail_prog = '/usr/sbin/sendmail' ;
# This script was generated automatically by Perl Builder(tm): http://www.solutionsoft.com
# ***ENDAUTOGEN:HEADER*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:INPUT*** Do NOT modify this line!! Do NOT enter custom code in this section.
&GetFormInput;
# The intermediate variables below make your script more readable
# but somewhat less efficient since they are not really necessary.
# If you do not want to use these variables, clear the
# Intermediate Variables checkbox in the Tools Options dialog box, CGI Wizard tab.
$name = $field{'name'} ;
$address = $field{'address'} ;
$city = $field{'city'} ;
$zip = $field{'zip'} ;
$telephone = $field{'telephone'} ;
$email = $field{'email'} ;
$price = $field{'price'} ;
$features = $field{'features'} ;
$details = $field{'details'} ;
$upload = $field{'upload'} ;
$check = $field{'check'} ;
$submit = $field{'submit'} ;
# ***ENDAUTOGEN:INPUT*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:VALIDATE*** Do NOT modify this line!! Do NOT enter custom code in this section.
# ***ENDAUTOGEN:VALIDATE*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:LOGFILE*** Do NOT modify this line!! Do NOT enter custom code in this section.
# ***ENDAUTOGEN:LOGFILE*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:EMAIL*** Do NOT modify this line!! Do NOT enter custom code in this section.
$recip = "wmzlotoff@yahoo.com" ;
if (($recip =~ /(@.*@)(..)(@.)(.@)(^.)/) ($recip !~ /^.+@([?)[a-zA-Z0-9-.]+.([a-zA-Z0-9]+)(]?)$/)) {
print "Fatal Error - Invalid email" ;
exit 0; }
open (MAIL, "$mail_prog -t" ;
print MAIL "To: $recipn";
print MAIL "Reply-to: webmaster@buyahome-phoenix.comn";
print MAIL "From: webmaster@buyahome-phoenix.comn";
print MAIL "Subject: add listingn";
print MAIL "nn";
print MAIL "Name:".$name."n" ;
print MAIL "Address:".$address."n" ;
print MAIL "City:".$city."n" ;
print MAIL "Zip:".$zip."n" ;
print MAIL "Telephone:".$telephone."n" ;
print MAIL "Email:".$email."n" ;
print MAIL "Price:".$price."n" ;
print MAIL "Features:".$features."n" ;
print MAIL "Details:".$details."n" ;
print MAIL "Upload:".$upload."n" ;
print MAIL "nn";
close (MAIL);
# ***ENDAUTOGEN:EMAIL*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:HTML*** Do NOT modify this line!! Do NOT enter custom code in this section.
print "Location: http://www.buyahome-phoenix.com/thankyou.htmlnURI: http://www.buyahome-phoenix.com/thankyou.htmlnn" ;
# ***ENDAUTOGEN:HTML*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:ERRPRINT*** Do NOT modify this line!! Do NOT enter custom code in this section.
# ***ENDAUTOGEN:ERRPRINT*** Do NOT modify this line!! You may enter custom code after this line.
# ***AUTOGEN:PARSE*** Do NOT modify this line!! Do NOT enter custom code in this section.
sub GetFormInput {
(*fval) = @_ if @_ ;
local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "" {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$name} .= " | | |