Results 1 to 2 of 2
Related
-
Form - checkboxes & file upload Forum: PHP Forum
Replies: 1 -
Upload logo/image in form Forum: CGI Perl Forum
Replies: 0 -
Script to keep latest upload date of files Forum: PHP Forum
Replies: 2 -
Large upload files causing parent directory to be deleted Forum: CGI Perl Forum
Replies: 0 -
Allowing users to upload files Forum: HTML Forum
Replies: 3
-
05-12-2012, 01:36 PM #1
How can I code this form to upload files
I like this script, but need to upload files with my forms. I also want to use captcha with it. The orig. coder's sit is shut now.
Thanks
Code:#!/usr/bin/perl ########################################################## # Form2Email.co.uk Xtra 17/Aug/2004 # © 1999-2004 Form2Email.co.uk # Script by Alexandre Golovkine ########################################################## # Instructions: http://www.Form2Email.co.uk/instructions/ # FAQ: http://www.Form2Email.co.uk/faq/ ########################################################## my $script_name = 'safemail.pl'; my $HTML_thankyou = 'http://www.'; my $to = '@'; my $from = 'Email'; my $mailprog = '/usr/sbin/sendmail'; my $subject = 'business'; ########################################################## # Advanced Settings Log details my $log = '0'; my $log_name = '0'; my $seperator = '##### log #####'; my $data_only = '0'; ########################################################## # Admin mode password my $username = "admin"; my $password = "danirw4333"; ########################################################## # Advanced Settings my $kill_image_buttons_value = 1; my $kill_html_tags = 1; my $subject_field = "Subject"; my $from_field_name = "Email"; my $from_field_name_error = "Data Error in $from_field_name"; my $max_message_length = 5000; my $max_message_error = "Your message is too long"; my $send_just_data = 0; ########################################################## # Advanced Settings Auto Responder my $auto_responder = 0; my $auto_responder_from = 'email@yourdomain.com'; my $auto_responder_message = "responder.txt"; my $auto_responder_subject = "Email from YourDomain.com"; ########################################################## # Advanced Settings Environmental values my $REMOTE_ADDR = 1; my $HTTP_USER_AGENT = 1; my $DATE = 1; ########################################################## # Advanced Settings SMTP email # use Net::SMTP; my $send_via_SMTP = 0; my $mailhost = 'smtp.com'; ########################################################## # Advanced Settings required fields my @required_fields = (); my @required_fields_numbers = (); my @required_fields_email = "Email"; my $error_fields_require = "Field is blank, it is required"; my $error_fields_numbers = "Only numbers"; my $error_fields_email = "email address is not valid"; my $error_title = "<b>Sorry, we need you to check the following</b>"; my $fontColor = "black"; my $fontSize = 3; my $fontFace = "Verdana"; my $return_message = "Please click 'back' on your browser and try again"; ########################################################## # Advanced Settings extra thank you page my $HTML_thankyou_field_name = ''; $ThankYou{'thankyoua'} = 'thankyoua.htm'; $ThankYou{'thankyoub'} = 'thankyoub.htm'; $ThankYou{'thankyouc'} = 'thankyouc.htm'; ########################################################## # Advanced Settings extra email address my $field_name_email = ''; my $sendToError = "Please select correct location"; $SendTo{'sales'} = 'sales.team@yourdomain.com'; $SendTo{'help'} = 'help.me@yourdomain.com'; $SendTo{'information'} = 'info@yourdomain.com'; ################################################################################## # Form2Email.co.uk © 1999 - 2004 Copyright # # The scripts are available for private and commercial use. # # You can use the scripts in any website you build. # # It is prohibited to sell the scripts in any format to anybody. # # The scripts may only be distributed by Form2Email.co.uk # # The redistribution of modified versions of the scripts is prohibited. # # Form2Email.co.uk accepts no responsibility or liability # # whatsoever for any damages however caused when using our services or scripts. # # By downloading and using this script you agree to the terms and conditions. # ################################################################################## @date=localtime(); $date[4]++; $date[5]+=1900; $date="$date[5]-$date[4]-$date[3]"; %FORM = parse_cgi(); if($FORM{mode} eq 'admin'){ if($FORM{login}){ if ($FORM{login} eq $username && $FORM{password} eq $password){$FORM{hash}=crypt($password,$username);} else{promt();} } elsif ($FORM{hash} ne crypt($password,$username)){promt()}; #read log file open(F, "$log_name") or error("Can't open log-file"); local $/; my $data = <F>; close F; $seperator.="\n"; @data = split($seperator, $data); #delete if act=delete if ($FORM{action} eq 'delete'){ @items =split(", ", $FORM{Item}); for(@items){$Items{$_}=1;} #error($Items{1}); my $i=1; my $a=0; my @new_data; for(@data){ unless($Items{($i)}){ $new_data[$a++] = $_ ; } $i++; } @data=@new_data; if($log){ open (LOG, ">$log_name") or error("Can't open log file"); print LOG join("$seperator",@data); close LOG; } print "Location: $script_name?mode=admin&hash=$FORM{hash}\n\n"; exit; } my $total = @data; my $i=1; my $txt = qq~ <script> function deleteItem(){ myform.submit(); } </script> <form name=myform><input type=hidden name=mode value=admin> <input type=hidden name=action value=delete> <input type=hidden name=hash value=$FORM{hash}> <table width=600><tr><th class=of align=center>Total Emails: $total</th></tr> <tr><td class=off align=right><a href=javascript:deleteItem()>delete marked messages</a> </td></tr>~; for(@data){ $_=~s/\n/<br>/g; $txt.= "<tr><td class=of> Email #$i</td></tr>"; $txt.= "<tr><td class=off>$_</td></tr>"; $txt.= "<tr><td class=off align=right><a href=$script_name?mode=admin&action=delete&Item=$i&hash=$FORM{hash}>delete</a> <input type=checkbox name=Item value=$i> </td></tr>"; $i++; } $txt.="</table></form>"; html_text($txt); exit; } push @required_fields,$field_name_email unless $to; push @required_fields_email,$from_field_name if $FORM{$from_field_name}; test_form(); my @to = (); my $logText = ""; foreach(@field){ if ($_ eq $from_field_name){ $from = $FORM{$from_field_name} if $FORM{$from_field_name}; error("$from_field_name_error") if length($FORM{$from_field_name})>40; error("$from_field_name_error") if $FORM{$from_field_name}=~m/:/s; error("$from_field_name_error") if $FORM{$from_field_name}=~m/Content-type/is; error("$from_field_name_error") if $FORM{$from_field_name}=~m/\n/is; $from =~ s/<([^>]|\n)*>//gs; $from =~ s/ //gs; $from =~ s/\n|\r//gs; $message.="$_: " unless $send_just_data; $message.="$FORM{$_}\n"; $logText.="$_: " unless $data_only; $logText.="$FORM{$_}\n"; } elsif ($_ eq $subject_field){$subject = $FORM{$subject_field} if $FORM{$subject_field};} elsif ($_ eq $HTML_thankyou_field_name){$HTML_thankyou = $ThankYou{$FORM{$HTML_thankyou_field_name}} if $ThankYou{$FORM{$HTML_thankyou_field_name}};} elsif ($_ eq $field_name_email){ if ($FORM{$field_name_email}){ my @mails = split(", ",$FORM{$field_name_email}); foreach(@mails){push @to, $SendTo{$_} if $SendTo{$_};} } } else{ $message.="$_: " unless $send_just_data; $message.="$FORM{$_}\n"; $logText.="$_: " unless $data_only; $logText.="$FORM{$_}\n"; } } #print "Content-type: text/html\n\n"; push @to, $to if $to && !@to; if ($REMOTE_ADDR){ $message.="REMOTE_ADDR: " unless $send_just_data; $message.="$ENV{REMOTE_ADDR}\n"; $logText.="REMOTE_ADDR: " unless $data_only; $logText.="$ENV{REMOTE_ADDR}\n"; } if ($HTTP_USER_AGENT){ $message.="HTTP_USER_AGENT: " unless $send_just_data; $message.="$ENV{HTTP_USER_AGENT}\n"; $logText.="HTTP_USER_AGENT: " unless $data_only; $logText.="$ENV{HTTP_USER_AGENT}\n"; } if ($DATE){ $message.="DATE: " unless $send_just_data; $message.="$date[2]:$date[1]:$date[0] $date\n"; $logText.="DATE: " unless $data_only; $logText.="$date[2]:$date[1]:$date[0] $date\n"; } error($sendToError) unless @to; error($max_message_error) if length($message)>$max_message_length; if($log){ $logText="To: ".join(", ", @to)."\nSubject: $subject\n".$logText; $logText="$seperator\n".$logText if -f $log_name; open (LOG, ">>$log_name") or error("Can't open log file"); print LOG $logText; close LOG; } foreach(@to){ male("$_", "$from", $subject, $message); } if($auto_responder && $FORM{$from_field_name}){ $FORM{$from_field_name} =~ s/<([^>]|\n)*>//g; $FORM{$from_field_name} =~ s/ //g; $FORM{$from_field_name} =~ s/ //gs; $FORM{$from_field_name} =~ s/\n|\r//gs; open(F, "$auto_responder_message") or error("Can't open message file"); my @message=<F>; close F; male("$FORM{$from_field_name}","$auto_responder_from",$auto_responder_subject, join('',@message)); } print "Location: $HTML_thankyou\n\n"; exit; ############################################################## sub error{ print "Content-type: text/html\n\n"; print "<html><head><title>Error</title></head><body><br><font color=$fontColor size=$fontSize face=$fontFace>$error_title<br><br>$_[0]<br>"; print "$return_message" if $_[1]; print "</font></body></html>"; exit; } sub parse_cgi{ my %FORM; my $name; my $value; my $content; my $a=0; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g if $kill_html_tags; $value =~ s/<([^>]|\n)*>//g if $kill_html_tags; if($FORM{$name}){$FORM{$name} = ", ".$value;} else{$FORM{$name} = $value; $field[$a++]=$name if $name ne 'thank_you' and !($kill_image_buttons_value && $name=~/(\.|\A)(x|y)\Z/);} } $a=0; $temp=$ENV{'QUERY_STRING'}; @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)= split (/=/,$item,2); $content =~ tr/+/ /; $content =~ s/%(..)/pack("c",hex($1))/ge; $content =~ s/<!--(.|\n)*-->//g if $kill_html_tags; $content =~ s/<([^>]|\n)*>//g if $kill_html_tags; if($FORM{$key}){$FORM{$key} .= ", ".$content;} else{$FORM{$key} = $content; $field[$a++]=$key if $key ne 'thank_you' and !($kill_image_buttons_value && $key=~/(\.|\A)(x|y)\Z/);} } return %FORM; } sub male{ if($send_via_SMTP){ $smtp = Net::SMTP->new($mailhost); $smtp->mail($_[1]); $smtp->to($_[0]); $smtp->data(); $smtp->datasend("To: $_[0]\n"); $smtp->datasend("From: $_[1]\n"); $smtp->datasend("Subject: $_[2]\n\n"); $smtp->datasend("\n"); $smtp->datasend("$_[3]\n"); $smtp->dataend(); $smtp->quit; } else{ open(MAIL,"|$mailprog -t"); print MAIL "To: $_[0]\n"; print MAIL "From: $_[1]\n"; print MAIL "Subject: $_[2]\n\n"; print MAIL "$_[3]\n"; close(MAIL); #print "To: $_[0]<br>"; } } sub test_form{ my $errors=''; foreach(@required_fields){ $errors.="ERROR FIELD < $_ >: $error_fields_require!<br>" if $FORM{$_} eq ""; } foreach(@required_fields_numbers){ $errors.="ERROR FIELD < $_ >: $error_fields_numbers!<br>" if $FORM{$_}=~m/\D/ or $FORM{$_} eq ''; } foreach(@required_fields_email){ $errors.="ERROR FIELD < $_ >: $error_fields_email!<br>" if $FORM{$_} !~m/\A\S+?\@\S+?\.\S+?\Z/; } error("$errors",1) if $errors; return; } sub get_record{ my $text = $_[0]; $text =~ s{<<(.*?)>>}{exists($INSERT{$1}) ? $INSERT{$1} : ""}gsex; return $text; } sub html_text{ print "Content-type: text/html\n\n" unless $type; print qq|<html> <head> <title>Form2email :: Admin Mode</title> <style> tr,td,body {font-family: Tahoma, Arial; font-size:10pt;} .of {border-style:solid; border-width: 1; border-color : #999999; background-color:#dddddd} .on {border-style:none;background-color:#ddeedd} .off {border-style:none;background-color:#f3f3f3} </style> </head> <body> $_[0] </body></html>|; exit; } sub promt{ html_text(qq| <br><br><br><br><center><form method=post action=$script_name> <input type=hidden name=mode value=admin> <table border=0 width=280> <tr><th colspan=2 class=of>Form2email :: Admin mode</th></tr> <tr class=on><td width=43% align=right>Login: </td> <td width=57%><input type=text name=login size=13></td></tr> <tr class=on><td align=right>Password: </td> <td><input type=password name=password size=13></td></tr> <tr class=on><td colspan=2 align=center><input type=submit></td></tr> </table></form></center>|); exit; } ################################################################################## # Form2Email.co.uk © 1999 - 2004 Copyright # # The scripts are available for private and commercial use. # # You can use the scripts in any website you build. # # It is prohibited to sell the scripts in any format to anybody. # # The scripts may only be distributed by Form2Email.co.uk # # The redistribution of modified versions of the scripts is prohibited. # # Form2Email.co.uk accepts no responsibility or liability # # whatsoever for any damages however caused when using our services or scripts. # # By downloading and using this script you agree to the terms and conditions. # ##################################################################################
Last edited by HTML; 07-13-2012 at 10:20 AM.
-
01-16-2013, 10:23 PM #2
Re: How can I code this form to upload files
You can not alter this code, you'll need an uploader program, then, you can implement a HREF-Link to the your Mailform Page (or reverse) in order to get File(s) oder Image(s) uploaded to a predefined Place on a Server.
If you need a working single or multi image-uploader, let me know, I have some with automatic thumbnail creation implemented (working on most unix systems) , if required. After upload, it returns to the Mailform Page, if requested.
The one I used last uploads up to 4 Images and creates 2 additional Thumbnail Sizes from each uploaded image. It can be used on most UNIX equipped Servers where Perl-Scripts are allowed to be used for such Tasks. It creates individual (Unix Time) 10-digit Numbers, the 2 Thumbs created carry the similar id-number as the original Image, but are located in different Folders. This enables EASY Handling and placing anywhere on Site Pages.
I cannot write any links here, so, you have to type my Username. followed by an info RMATION, into your Browser url field to, eventually, find an image uploader. Hidden behind a login window (beni/ben) (hans/hansi), enabling you to start a new auction or classified offer. Then, there it is...
Just go ahead, test it out. If you need one, let me know.
Good Luck
Ernie
Sorry Admin, how else could I offer help!?Last edited by Everyauction; 01-16-2013 at 10:28 PM. Reason: adding content
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum