On Jan 17, 2004, at 12:37 PM, zentara wrote:


On Sat, 17 Jan 2004 11:54:55 -0500, [EMAIL PROTECTED] (Gerry
Creighton) wrote:

So can you suggest where to add the form processing to the upload.cgi?
I'm good with Flash and actionscripting but am not totally in tune with
perl (yet).
The guy who wrote that megaupload progress bar script said that it can
be done but has yet to return my message on where to paste the form
processing code.
Thanks for the help!
Gerry

Well I have to give my email address to get the files...sorry. That's a sure way to get spam. If it isn't too big, you could post the cgi script you want to paste it into here. P.S. My email address I use here is just a spam bucket, don't send anything there, because I won't get it.

You need a cgi script to generate the form, a plain form won't
do. Why do you need this special FormBuilder anyways?
You should use this as an opportunity to write your own....
that's the only way to learn.



--
When life conspires against you, and no longer floats your boat,
Don't waste your time with crying, just get on your back and float.


Correct me if I'm wrong but this should be the form processing that I need. This should send the form info to me and to the person filling it out.
Let me know what's up.
Thanks alot!
Gerry



<code> #Standard variables which must be in every form : #email --> it submitter email address

#Example for form:
#Your email address : <input type="text" name="email"><br>
#Your name          : <input type="text" name="name">

#if field written in format as <input type="text" name="name_val">
#that mean what script will be generate error if field name_val empty.

#<input type="hidden" name="order" value="name,email,url">
#it define order of fields in email

#Configure script here:

#You must define = where uploaded files will be stored.
#1. unix/nt path to uploaded files directory (must be chmoded to 777)
#2. full url of uploaded files directory
$files_path="/u/web/mydomainname/uploads";
$files_url ="http://www.mydomainname.com/uploads";;

#Which file extensions must support script?

@ext=("gif","jpg","jpeg","tif","tiff","zip","pdf","sit","psd","mp3","mov ","mp4","avi","ppt","doc","ai","qxd","eps","ttf","pub","sea");

#Maximum size of one uploaded file?

$maxsize=100000000; # 100 000 bytes by default

#How much files can be uploaded? Name it as file1..file12 for example
$maxfiles=2;

#File must be allways uploaded with form or not?
#Specify 0 - if your form can be without file or 1 - if as minimum uploading
# of one file is requied


$requpload="1";

#Mailing. Send emails to admin/user via smtp or sendmail? Set only one!

$sendmail="/usr/lib/sendmail";
$smtp="";

#Admin email address.

$admin_email='[EMAIL PROTECTED]';

#Enter list of your websites which can call this script.

@domains=('domainName.com','IPNumber');

#Enable autoresponder? If set to 1, script will be send email to submitter.

$autoresponder="1";

#Subject for autoresponder message

$asubject='Thank you for uploading your files!';

#Autoresponder message

#Do we need to save information about submitted files/submitter email
#in database? If yes - set to unix/nt path to file

$store=""; #Example with db : $store="./emails.db";

#End of configuration section

#Process form
#$efrom - this address of form submitter

$recipient=$CGI{'recepient'};
if (!$recepient) {$recipient=$admin_email;}else{delete $CGI{'recipient'};}


@order=split(/\,/,$CGI{'order'}); #Order of form

#Process form after this images with urls.

$redirect=$CGI{'redirect'};
if ($redirect) {delete $CGI{'redirect'};}


$msg1=""; #Form fields $msg2=""; #Files urls $msg3=""; #File name if ($order[0]) { delete $CGI{'order'}; foreach $item (@order) {$msg1.="$item : $CGI{$item}\n";} }else{ foreach $key (sort keys %CGI) { if ($key !~ /file/is) {$msg1.="$key : $CGI{$key}\n";} } }

foreach $fo (@fname) {
$msg2.="$files_url/$fo\n";
$msg3.="$filename $fo\n";
}

$vrb=qq~Hello!

Visitor from $ENV{'REMOTE_ADDR'} has submitted form and attached $total files.

-------------------------------------------------
Job Information :
$msg1
-------------------------------------------------
Uploaded files :
$msg2

Best Regards,
Your uploader script
~;
#Autoresponder message

$amessage=qq~
Hello!

Thanks for uploading your job. We have received your job and will contact you with any questions.
You submitted the following:
-------------------------------------------------
Job Information :
$msg1
-------------------------------------------------
Uploaded files :
$msg3


Best Regards,
$admin_email
~;

#Send forms and autoresponder message if need
#$sendmail, $smtp

sendmail($sendmail,$smtp,"New form is submitted",$recipient,$efrom,$efrom,"New form is submitted",$vrb,0);

if ($autoresponder) {
sendmail($sendmail,$smtp,$asubject,$efrom,$recipient,$recipient,$asubjec t,$amessage,0);
}



#Headers if ($redirect) { print "Location: $redirect \n\n"; }else{ print "Content-type:text/html \n\n"; print load_template("submit-ok.html"); } exit;

}
sub load_template{my ($filename,$text,%values,$name,$value);$filename=shift;$name=shift;%valu es=%$name;$text="";open(IN,"<$filename") or error("Cannot open $templates/$filename : Reason $!");while(<IN>){chomp;$text.=$_;}close IN;while($text =~ m/\<\%(.*?)\%\>/gsi) {$name=$1;if (exists($values{$name})) {$value=$values{$name};}else{$value="";}$text =~ s/<\%$name\%>/$value/g;}return $text;}
sub error{$mes=shift;print qq~Content-type:text/html \n\n <html><font face="Verdana" size="2"><center><b>Error</b> : $mes<br><br><a href="javascript:history.go(-1)">Back</a>.<br><br><br><small>(c)-2001 <a href="http://www.mycgiscripts.com";>www.mycgiscripts.com</a>~;exit;}
sub Parse_Data {
local($raw_data,@items,$key,$value);


$raw_data = &Parse_Method;

    # Split different "NAME" and their values.
    @items = split('&', $raw_data);

    # For each list of "NAME=its_value".
    for (@items) {

        $_ =~ tr/+/ /;
        ($key,$value) = split('=',$_,2);

        # The %xx hex numbers are converted to alphanumeric.
        $key   =~ s/%(..)/pack("C", hex($1))/eg;
        $value =~ s/%(..)/pack("C", hex($1))/eg;
        if (grep(/^$key$/, keys(%CGI))) {
          if (@{$CGI{$key}} > 0) {
            push(@{$CGI{$key}}, "$value");
          }
          else {
            $arrvalue = $CGI{$key};
            undef $CGI{$key};
            $CGI{$key}[0] = $arrvalue;
            push(@{$CGI{$key}}, "$value");
          }
        }
        else {
          $CGI{$key} = $value;
        }
     }
}

sub Print_Head {
    print "Content-Type: text/html\n\n";
}

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;
}
}


sub Parse_Method {
    local($buffer);

if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
return $buffer;
}
elsif ($ENV{'REQUEST_METHOD'} eq "GET") {
return $ENV{'QUERY_STRING'};
}
else {
return 0;
}
}
sub init_smtp{$smtp_server=shift;use Socket;$proto = (getprotobyname('tcp'))[2];$port = getservbyname('smtp', 'tcp');$smtp_server =~ s/^\s+//g;$smtp_server =~ s/\s+$//g;$smtpaddr = ($smtp_server =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) ? pack('C4',$1,$2,$3,$4) : (gethostbyname($smtp_server))[4]; if (!$smtpaddr) {return "SMTP host not found!";}return "ok";}
sub sendmail{ my @send_to; my $answer;@send_to = @_;if ($send_to[0]) { $answer=sendmail_smail($send_to[0],@send_to[2..8]); return $answer; }if ($send_to[1]) { if (!$smtpaddr) { $answer=init_smtp($send_to[1]); if ($answer ne "ok") {return "$answer";} } $answer=sendmail_smtp(@send_to[2..8]); return $answer; }return "Error! Must be specifed one from emailing methods!";}
sub sendmail_smail{my @send_to;@send_to = @_; open (SM, "|$send_to[0] -oeq -t") or return "Error sending mail! Reason : $!";print SM "From: $send_to[3]\n"; print SM "To: $send_to[2]\n";print SM "Reply-to: $send_to[3]\n"; print SM "X-Mailer: Control panel script (http://www.mycgiscripts.com/)\n"; print SM "Subject: $send_to[5]\n\n";$send_to[6] =~ s/\r/$CRLF/g; print SM $send_to[6]; print SM "\n\n.\n"; close SM;return "ok";}
sub sendmail_smtp{my @send_to;@send_to = @_;$CRLF = "\015\012";socket(SOCK, AF_INET, SOCK_STREAM, $proto) or return "Socket operation failed : Reason $!";connect(SOCK, pack('Sna4x8', AF_INET, $port, $smtpaddr)) or return "Connection failed : Reason $!";my($oldfh) = select(SOCK); $| = 1; select($oldfh);$_ = <SOCK>; if (/^[45]/) { close SOCK; return "Service not available : Reason $!"; } print SOCK "helo localhost$CRLF"; $_ = <SOCK>; if (/^[45]/) { close SOCK; return "Communication error : Reason $!"; } print SOCK "mail from: <", $send_to[2], ">$CRLF"; $_ = <SOCK>; if (/^[45]/) { close SOCK; return "Communication error : Reason $!"; } foreach (split(/,/, $send_to[1])) {(/<(.*)>/) ? print SOCK "rcpt to: $1$CRLF" : print SOCK "rcpt to: <$_>$CRLF"; $_ = <SOCK>; if (/^[45]/) { close SOCK;return "Unknown user. Email address not valid"; } }print SOCK "data$CRLF";$_ = <SOCK>; if (/^[45]/) { close SOCK; return "Communication error : Reason $!"; }print SOCK "To: $send_to[0] <$send_to[1]>", $CRLF;print SOCK "From: $send_to[2]",$CRLF;print SOCK "Reply-to: $send_to[3]",$CRLF;print SOCK "Content-Type: text/plain; charset=us-ascii\n";print SOCK "X-Mailer: Control panel script (http://www.mycgiscripts.com/)$CRLF";print SOCK "Content-Type: text/html\n" if ($send_to[6]);print SOCK "Subject: $send_to[4]",$CRLF,$CRLF;
$send_to[5] =~ s/\r/$CRLF/g;print SOCK $send_to[5];print SOCK $CRLF, '.', $CRLF;$_ = <SOCK>; if (/^[45]/) { close SOCK;return "Transfer failed : Reason $!"; }print SOCK "quit", $CRLF;$_ = <SOCK>;close SOCK;return"ok";}
</code>



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to