Solved

How can I upload an image file?

Posted on 2002-04-01
44
537 Views
Last Modified: 2012-05-04
Hi

I´m not a programmer, but a designer although I just read a manual in perl and cgi I can´t seem to make this script to work. I want to upload a file from a form, but it keeps sending errors, the last modification I made turn out like this:

#!/usr/local/bin/perl


# Define Variables                                                

# $mailprog defines the location of your sendmail program on your unix       #
# system.                                                                    #

$mailprog = '/usr/lib/sendmail';

# @referers allows forms to be located only on servers which are defined     #
# in this field.  This security fix from the last version which allowed      #
# anyone on any server to use your FormMail script on their web site.        #

@referers = ('vantha@prodigy.net.mx','selectivedirectory.hypermart.net','www.hypermart.net, macas69@yahoo.com');

# @recipients defines the e-mail addresses or domain names that e-mail can   #
# be sent to.  This must be filled in correctly to prevent SPAM and allow    #
# valid addresses to receive e-mail.  Read the documentation to find out how #
# this variable works!!!  It is EXTREMELY IMPORTANT.                         #
@recipients = @referers;

# ACCESS CONTROL FIX: Peter D. Thompson Yezek                                #
# @valid_ENV allows the sysadmin to define what environment variables can    #
# be reported via the env_report directive.  This was implemented to fix     #
# the problem reported at http://www.securityfocus.com/bid/1187              #

@valid_ENV = ('REMOTE_HOST','REMOTE_ADDR','REMOTE_USER','HTTP_USER_AGENT');

# Done                                                                       #
#upload

local $filePath = $query->param('file');

print "Content-type:text/html\n\n";
&upload_pic;


sub upload_pic
{
   $dir = "http://selectivedirectory.hypermart.net/cgi-bin/archivos/";
   $filename = $filePath;
   $filename =~ s/.+\\([^\\]+)$|.+\/([^\/]+)$/\1/;
   $saveLoc = $dir.$filename;

   #Save (upload) file
   open(MYFILE,"> $saveLoc") || die $!;
   binmode MYFILE;
   while($bytesread = read($filePath,$data,1024))
   {
       $size1+=$bytesread;
       print MYFILE $data;
   }
   close(MYFILE);
   close($filePath);

##############################################################################

# Check Referring URL
&check_url;

# Retrieve Date
&get_date;

# Parse Form Contents
&parse_form;

# Check Required Fields
&check_required;

# Send E-Mail
&send_mail;

# Return HTML Page or Redirect User
&return_html;

sub check_url {

    # Localize the check_referer flag which determines if user is valid.     #
    local($check_referer) = 0;

    # If a referring URL was specified, for each valid referer, make sure    #
    # that a valid referring URL was passed to FormMail.                     #

    if ($ENV{'HTTP_REFERER'}) {
        foreach $referer (@referers) {
            if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) {
                $check_referer = 1;
                last;
            }
        }
    }
    else {
        $check_referer = 1;
    }

    # If the HTTP_REFERER was invalid, send back an error.                   #
    if ($check_referer != 1) { &error('bad_referer') }
}

sub get_date {

    # Define arrays for the day of the week and month of the year.           #
    @days   = ('Sunday','Monday','Tuesday','Wednesday',
               'Thursday','Friday','Saturday');
    @months = ('January','February','March','April','May','June','July',
               'August','September','October','November','December');

    # Get the current time and format the hour, minutes and seconds.  Add    #
    # 1900 to the year to get the full 4 digit year.                         #
    ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
    $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
    $year += 1900;

    # Format the date.                                                       #
    $date = "$days[$wday], $months[$mon] $mday, $year at $time";

}

sub parse_form {

    # Define the configuration associative array.                            #
    %Config = ('recipient','',          'subject','',
               'email','',              'realname','',
               'redirect','',           'bgcolor','',
               'background','',         'link_color','',
               'vlink_color','',        'text_color','',
               'alink_color','',        'title','',
               'sort','',               'print_config','',
               'required','',           'env_report','',
               'return_link_title','',  'return_link_url','',
               'print_blank_fields','', 'missing_fields_redirect','');

    # Determine the form's REQUEST_METHOD (GET or POST) and split the form   #
    # fields up into their name-value pairs.  If the REQUEST_METHOD was      #
    # not GET or POST, send an error.                                        #
    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        # Split the name-value pairs
        @pairs = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
        # Get the input
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
        # Split the name-value pairs
        @pairs = split(/&/, $buffer);
    }
    else {
        &error('request_method');
    }

    # For each name-value pair:                                              #
    foreach $pair (@pairs) {

        # Split the pair up into individual variables.                       #
        local($name, $value) = split(/=/, $pair);
 
        # Decode the form encoding on the name and value variables.          #
        $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;

        # If they try to include server side includes, erase them, so they
        # aren't a security risk if the html gets returned.  Another
        # security hole plugged up.
        $value =~ s/<!--(.|\n)*-->//g;

        # If the field name has been specified in the %Config array, it will #
        # return a 1 for defined($Config{$name}}) and we should associate    #
        # this value with the appropriate configuration variable.  If this   #
        # is not a configuration form field, put it into the associative     #
        # array %Form, appending the value with a ', ' if there is already a #
        # value present.  We also save the order of the form fields in the   #
        # @Field_Order array so we can use this order for the generic sort.  #
        if (defined($Config{$name})) {
            $Config{$name} = $value;
        }
        else {
            if ($Form{$name} && $value) {
                $Form{$name} = "$Form{$name}, $value";
            }
            elsif ($value) {
                push(@Field_Order,$name);
                $Form{$name} = $value;
            }
        }
    }

    # The next six lines remove any extra spaces or new lines from the       #
    # configuration variables, which may have been caused if your editor     #
    # wraps lines after a certain length or if you used spaces between field #
    # names or environment variables.                                        #
    $Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'required'} =~ s/(\s+)?\n+(\s+)?//g;
    $Config{'env_report'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'env_report'} =~ s/(\s+)?\n+(\s+)?//g;
    $Config{'print_config'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
    $Config{'print_config'} =~ s/(\s+)?\n+(\s+)?//g;

    # Split the configuration variables into individual field names.         #
    @Required = split(/,/,$Config{'required'});
    @Env_Report = split(/,/,$Config{'env_report'});
    @Print_Config = split(/,/,$Config{'print_config'});

    # ACCESS CONTROL FIX: Only allow ENV variables in @valid_ENV in          #
    # @Env_Report for security reasons.                                      #
    foreach $env_item (@Env_Report) {
        foreach $valid_item (@valid_ENV) {
            if ( $env_item eq $valid_item ) { push(@temp_array, $env_item) }
        }
    }
    @Env_Report = @temp_array;
}

sub check_required {

    # Localize the variables used in this subroutine.                        #
    local($require, @error);

    if ($Config{'subject'} =~ /(\n|\r)/m ||
        $Config{'recipient'} =~ /(\n|\r)/m) {
        &error('no_recipient');
    }

    if (!$Config{'recipient'}) {
        if (!defined(%Form)) { &error('bad_referer') }
        else                 { &error('no_recipient') }
    }
    else {
        # This block of code requires that the recipient address end with    #
        # a valid domain or e-mail address as defined in @recipients.        #
        $valid_recipient = 0;
        foreach $send_to (split(/,/,$Config{'recipient'})) {
            foreach $recipient (@recipients) {
                if ($send_to =~ /$recipient$/i) {
                    push(@send_to,$send_to); last;
                }
            }
        }
        if ($#send_to < 0) { &error('no_recipient') }
        $Config{'recipient'} = join(',',@send_to);
    }

    # For each require field defined in the form:                            #
    foreach $require (@Required) {

        # If the required field is the email field, the syntax of the email  #
        # address if checked to make sure it passes a valid syntax.          #
        if ($require eq 'email' && !&check_email($Config{$require})) {
            push(@error,$require);
        }

        # Otherwise, if the required field is a configuration field and it   #
        # has no value or has been filled in with a space, send an error.    #
        elsif (defined($Config{$require})) {
            if (!$Config{$require}) {
                push(@error,$require);
            }
        }

        # If it is a regular form field which has not been filled in or      #
        # filled in with a space, flag it as an error field.                 #
        elsif (!$Form{$require}) {
            push(@error,$require);
        }
    }

    # If any error fields have been found, send error message to the user.   #
    if (@error) { &error('missing_fields', @error) }
}

sub return_html {
    # Local variables used in this subroutine initialized.                   #
    local($key,$sort_order,$sorted_field);

    # If redirect option is used, print the redirectional location header.   #
    if ($Config{'redirect'}) {
        print "Location: $Config{'redirect'}\n\n";
    }

    # Otherwise, begin printing the response page.                           #
    else {

        # Print HTTP header and opening HTML tags.                           #
        print "Content-type: text/html\n\n";
        print "<html>\n <head>\n";

        # Print out title of page                                            #
        if ($Config{'title'}) { print "  <title>$Config{'title'}</title>\n" }
        else                  { print "  <title>Thank You</title>\n"        }

        print " </head>\n <body";

        # Get Body Tag Attributes                                            #
        &body_attributes;

        # Close Body Tag                                                     #
        print ">\n  <center>\n";

        # Print custom or generic title.                                     #
        if ($Config{'title'}) { print "   <h1>$Config{'title'}</h1>\n" }
        else { print "   <h1>Thank You For Filling Out This Form</h1>\n" }

        print "</center>\n";

        print "Below is what you submitted to $Config{'recipient'} on ";
        print "$date<p><hr size=1 width=75\%><p>\n";

        # Sort alphabetically if specified:                                  #
        if ($Config{'sort'} eq 'alphabetic') {
            foreach $field (sort keys %Form) {

                # If the field has a value or the print blank fields option  #
                # is turned on, print out the form field and value.          #
                if ($Config{'print_blank_fields'} || $Form{$field}) {
                    print "<b>$field:</b> $Form{$field}<p>\n";
                }
            }
        }

        # If a sort order is specified, sort the form fields based on that.  #
        elsif ($Config{'sort'} =~ /^order:.*,.*/) {

            # Set the temporary $sort_order variable to the sorting order,   #
            # remove extraneous line breaks and spaces, remove the order:    #
            # directive and split the sort fields into an array.             #
            $sort_order = $Config{'sort'};
            $sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
            $sort_order =~ s/(\s+)?\n+(\s+)?//g;
            $sort_order =~ s/order://;
            @sorted_fields = split(/,/, $sort_order);

            # For each sorted field, if it has a value or the print blank    #
            # fields option is turned on print the form field and value.     #
            foreach $sorted_field (@sorted_fields) {
                if ($Config{'print_blank_fields'} || $Form{$sorted_field}) {
                    print "<b>$sorted_field:</b> $Form{$sorted_field}<p>\n";
                }
            }
        }

        # Otherwise, default to the order in which the fields were sent.     #
        else {

            # For each form field, if it has a value or the print blank      #
            # fields option is turned on print the form field and value.     #
            foreach $field (@Field_Order) {
                if ($Config{'print_blank_fields'} || $Form{$field}) {
                    print "<b>$field:</b> $Form{$field}<p>\n";
                }
            }
        }

        print "<p><hr size=1 width=75%><p>\n";

        # Check for a Return Link and print one if found.                    #
        if ($Config{'return_link_url'} && $Config{'return_link_title'}) {
            print "<ul>\n";
            print "<li><a href=\"$Config{'return_link_url'}\">$Config{'return_link_title'}</a>\n";
            print "</ul>\n";
        }

        # Print the page footer.                                             #
        print <<"(END HTML FOOTER)";
        <hr size=1 width=75%><p>
        <center><font size=-1><a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a> V1.9 &copy; 1995 - 2001  Matt Wright<br>
A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive, Inc.</a></font></center>
        </body>
       </html>
(END HTML FOOTER)
    }
}

sub send_mail {
    # Localize variables used in this subroutine.                            #
    local($print_config,$key,$sort_order,$sorted_field,$env_report);

    # Open The Mail Program
    open(MAIL,"|$mailprog -t");

    print MAIL "To: $Config{'recipient'}\n";
    print MAIL "From: $Config{'email'} ($Config{'realname'})\n";

    # Check for Message Subject
    if ($Config{'subject'}) { print MAIL "Subject: $Config{'subject'}\n\n" }
    else                    { print MAIL "Subject: WWW Form Submission\n\n" }

    print MAIL "Below is the result of your feedback form.  It was submitted by\n";
    print MAIL "$Config{'realname'} ($Config{'email'}) on $date\n";
    print MAIL "-" x 75 . "\n\n";

    if (@Print_Config) {
        foreach $print_config (@Print_Config) {
            if ($Config{$print_config}) {
                print MAIL "$print_config: $Config{$print_config}\n\n";
            }
        }
    }

    # Sort alphabetically if specified:                                      #
    if ($Config{'sort'} eq 'alphabetic') {
        foreach $field (sort keys %Form) {

            # If the field has a value or the print blank fields option      #
            # is turned on, print out the form field and value.              #
            if ($Config{'print_blank_fields'} || $Form{$field} ||
                $Form{$field} eq '0') {
                print MAIL "$field: $Form{$field}\n\n";
            }
        }
    }

    # If a sort order is specified, sort the form fields based on that.      #
    elsif ($Config{'sort'} =~ /^order:.*,.*/) {

        # Remove extraneous line breaks and spaces, remove the order:        #
        # directive and split the sort fields into an array.                 #
        $Config{'sort'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
        $Config{'sort'} =~ s/(\s+)?\n+(\s+)?//g;
        $Config{'sort'} =~ s/order://;
        @sorted_fields = split(/,/, $Config{'sort'});

        # For each sorted field, if it has a value or the print blank        #
        # fields option is turned on print the form field and value.         #
        foreach $sorted_field (@sorted_fields) {
            if ($Config{'print_blank_fields'} || $Form{$sorted_field} ||
                $Form{$sorted_field} eq '0') {
                print MAIL "$sorted_field: $Form{$sorted_field}\n\n";
            }
        }
    }

    # Otherwise, default to the order in which the fields were sent.         #
    else {

        # For each form field, if it has a value or the print blank          #
        # fields option is turned on print the form field and value.         #
        foreach $field (@Field_Order) {
            if ($Config{'print_blank_fields'} || $Form{$field} ||
                $Form{$field} eq '0') {
                print MAIL "$field: $Form{$field}\n\n";
            }
        }
    }

    print MAIL "-" x 75 . "\n\n";

    # Send any specified Environment Variables to recipient.                 #
    foreach $env_report (@Env_Report) {
        if ($ENV{$env_report}) {
            print MAIL "$env_report: $ENV{$env_report}\n";
        }
    }

    close (MAIL);
}

sub check_email {
    # Initialize local email variable with input to subroutine.              #
    $email = $_[0];

    # If the e-mail address contains:                                        #
    if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||

        # the e-mail address contains an invalid syntax.  Or, if the         #
        # syntax does not match the following regular expression pattern     #
        # it fails basic syntax verification.                                #

        $email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/) {

        # Basic syntax requires:  one or more characters before the @ sign,  #
        # followed by an optional '[', then any number of letters, numbers,  #
        # dashes or periods (valid domain/IP characters) ending in a period  #
        # and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers    #
        # (for IP addresses).  An ending bracket is also allowed as it is    #
        # valid syntax to have an email address like: user@[255.255.255.0]   #

        # Return a false value, since the e-mail address did not pass valid  #
        # syntax.                                                            #
        return 0;
    }

    else {

        # Return a true value, e-mail verification passed.                   #
        return 1;
    }
}

sub body_attributes {
    # Check for Background Color
    if ($Config{'bgcolor'}) { print " bgcolor=\"$Config{'bgcolor'}\"" }

    # Check for Background Image
    if ($Config{'background'}) { print " background=\"$Config{'background'}\"" }

    # Check for Link Color
    if ($Config{'link_color'}) { print " link=\"$Config{'link_color'}\"" }

    # Check for Visited Link Color
    if ($Config{'vlink_color'}) { print " vlink=\"$Config{'vlink_color'}\"" }

    # Check for Active Link Color
    if ($Config{'alink_color'}) { print " alink=\"$Config{'alink_color'}\"" }

    # Check for Body Text Color
    if ($Config{'text_color'}) { print " text=\"$Config{'text_color'}\"" }
}

sub error {
    # Localize variables and assign subroutine input.                        #
    local($error,@error_fields) = @_;
    local($host,$missing_field,$missing_field_list);

    if ($error eq 'bad_referer') {
        if ($ENV{'HTTP_REFERER'} =~ m|^https?://([\w\.]+)|i) {
            $host = $1;
            print <<"(END ERROR HTML)";
Content-type: text/html

<html>
 <head>
  <title>Bad Referrer - Access Denied</title>
 </head>
 <body bgcolor=#FFFFFF text=#000000>
  <center>
   <table border=0 width=600 bgcolor=#9C9C9C>
    <tr><th><font size=+2>Bad Referrer - Access Denied</font></th></tr>
   </table>
   <table border=0 width=600 bgcolor=#CFCFCF>
    <tr><td>The form attempting to use
     <a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a>
     resides at <tt>$ENV{'HTTP_REFERER'}</tt>, which is not allowed to access
     this cgi script.<p>

     If you are attempting to configure FormMail to run with this form, you need
     to add the following to \@referers, explained in detail in the README file.<p>

     Add <tt>'$host'</tt> to your <tt><b>\@referers</b></tt> array.<hr size=1>
     <center><font size=-1>
      <a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a> V1.9 &copy; 1995 - 2001  Matt Wright<br>
      A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive, Inc.</a>
     </font></center>
    </td></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
        }
        else {
            print <<"(END ERROR HTML)";
Content-type: text/html

<html>
 <head>
  <title>FormMail v1.9</title>
 </head>
 <body bgcolor=#FFFFFF text=#000000>
  <center>
   <table border=0 width=600 bgcolor=#9C9C9C>
    <tr><th><font size=+2>FormMail</font></th></tr>
   </table>
   <table border=0 width=600 bgcolor=#CFCFCF>
    <tr><th><tt><font size=+1>Copyright 1995 - 2001 Matt Wright<br>
        Version 1.9 - Released August 3, 2001<br>
        A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive,
        Inc.</a></font></tt></th></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
        }
    }

    elsif ($error eq 'request_method') {
            print <<"(END ERROR HTML)";
Content-type: text/html

<html>
 <head>
  <title>Error: Request Method</title>
 </head>
 <body bgcolor=#FFFFFF text=#000000>
  <center>
   <table border=0 width=600 bgcolor=#9C9C9C>
    <tr><th><font size=+2>Error: Request Method</font></th></tr>
   </table>
   <table border=0 width=600 bgcolor=#CFCFCF>
    <tr><td>The Request Method of the Form you submitted did not match
     either <tt>GET</tt> or <tt>POST</tt>.  Please check the form and make sure the
     <tt>method=</tt> statement is in upper case and matches <tt>GET</tt> or <tt>POST</tt>.<p>

     <center><font size=-1>
      <a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a> V1.9 &copy; 1995 - 2001  Matt Wright<br>
      A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive, Inc.</a>
     </font></center>
    </td></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
    }

    elsif ($error eq 'no_recipient') {
            print <<"(END ERROR HTML)";
Content-type: text/html

<html>
 <head>
  <title>Error: Bad/No Recipient</title>
 </head>
 <body bgcolor=#FFFFFF text=#000000>
  <center>
   <table border=0 width=600 bgcolor=#9C9C9C>
    <tr><th><font size=+2>Error: Bad/No Recipient</font></th></tr>
   </table>
   <table border=0 width=600 bgcolor=#CFCFCF>
    <tr><td>There was no recipient or an invalid recipient specified in the data sent to FormMail.  Please
     make sure you have filled in the <tt>recipient</tt> form field with an e-mail
     address that has been configured in <tt>\@recipients</tt>.  More information on filling in <tt>recipient</tt> form fields and variables can be
     found in the README file.<hr size=1>

     <center><font size=-1>
      <a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a> V1.9 &copy; 1995 - 2001  Matt Wright<br>
      A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive, Inc.</a>
     </font></center>
    </td></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
    }

    elsif ($error eq 'missing_fields') {
        if ($Config{'missing_fields_redirect'}) {
            print "Location: $Config{'missing_fields_redirect'}\n\n";
        }
        else {
            foreach $missing_field (@error_fields) {
                $missing_field_list .= "      <li>$missing_field\n";
            }

            print <<"(END ERROR HTML)";
Content-type: text/html

<html>
 <head>
  <title>Error: Blank Fields</title>
 </head>
  <center>
   <table border=0 width=600 bgcolor=#9C9C9C>
    <tr><th><font size=+2>Error: Blank Fields</font></th></tr>
   </table>
   <table border=0 width=600 bgcolor=#CFCFCF>
    <tr><td>The following fields were left blank in your submission form:<p>
     <ul>
$missing_field_list
     </ul><br>

     These fields must be filled in before you can successfully submit the form.<p>
     Please use your browser's back button to return to the form and try again.<hr size=1>
     <center><font size=-1>
      <a href="http://www.worldwidemart.com/scripts/formmail.shtml">FormMail</a> V1.9 &copy; 1995 - 2001  Matt Wright<br>
      A Free Product of <a href="http://www.worldwidemart.com/scripts/">Matt's Script Archive, Inc.</a>
     </font></center>
    </td></tr>
   </table>
  </center>
 </body>
</html>
(END ERROR HTML)
        }
    }

    exit;
}
}

and the error I´m getting is:

Can't call method "param" on an undefined value at /home/cgi-bin/headh1.pl line 56.

local $filePath = $query->param('file');

Can someone tell me why isn't it working and what can I do to fix it?

Also I would like to set an autoresponse ...
0
Comment
Question by:nadiassdcg
  • 25
  • 18
44 Comments
 
LVL 3

Expert Comment

by:Tsvetomir
Comment Utility
to use
"$query->param('file')"    ## (this is function from CGI.pm)
you have to add in the begginig of your script:

use CGI;
$query=new CGI;




But the whole script also won't work because formmail.pl (which you are useing to send email) works just with "application/x-www-form-urlencoded" forms .To upload binary file you need form of type : "multipart/form-data"

(<FORM name="form" method="post" action="http://mydomain.com/cgi-bin/script.cgi" enctype="multipart/form-data">)

formmail.pl can't parse parameters send by "multipart/form-data"
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..but it keeps sending errors, the last modification  I made turn out like this:..."

Can you post the URL of the server where one can see this error first hand?

Also, Here is a sample script that i would like you to test on your server.

Let me know what output you can see on your server.

=====hello.pl
#!/usr/local/bin/perl

$|++;

print "Content-type: text/html\n\n";

use CGI;

$q=new CGI;

print "All ok<BR>\";


0
 

Author Comment

by:nadiassdcg
Comment Utility
Ok, then this won´t work ...

Do I start all over again?

I wanted to allow users to send a form with an atachment file, cause I couldn´t find a way to do so I decided to upload the file. Also I want to add required fields, and send both a copy of the information they filled in to my email adress and to send the user an autoresponse telling him that we received the information and will contact him briefly.

Any suggestions?
0
 

Author Comment

by:nadiassdcg
Comment Utility
maneshr

the adress of my webpage is http://selectivedirectory.hypermart.net

I'll check what happens with the script and tell you later

Thanks
0
 

Author Comment

by:nadiassdcg
Comment Utility
Ok, I runned hello.pl

#!/usr/local/bin/perl

$|++;

print "Content-type: text/html\n\n";

use CGI;

$q=new CGI;

print "All ok<BR>\";

And I got:

[500] Error - Internal Server Error

The script you're trying to access has suffered a fatal error.
View the error log. Possible Reasons
The script you were trying to use is misconfigured in some way, and cannot complete the task as it should.
The server is experiencing some technical problems. You should try again shortly.
Debugging Information:
Premature end of script headers: /data1/hm/selectivedirectory/cgi-bin/hello.pl

CGI Error Log

Here you can view any recent CGI errors that were logged.

Can't find string terminator '"' anywhere before EOF at /home/cgi-bin/hello.pl line 11.

What does this means?

Can you help me?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..the adress of my webpage is http://selectivedirectory.hypermart.net.."
Super!!! Thanks.

"..[500] Error - Internal Server Error .."

REPLACE...

print "All ok<BR>\";

WITH...

print "All ok<BR>";

Let me know how it works for you.

0
 

Author Comment

by:nadiassdcg
Comment Utility
All ok

: )

You can see the form I´m talking about in:  

http://selectivedirectory.hypermart.net/htm/headhunters.htm

Thanks
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..All ok."
Excellent!! That is good news indeed!!

Based on the output i can confirm that you have the CGI perl module installed on your server.

Since you are using hypermart, i am not sure if you can use sendmail.

Hypermart has a program called qmail instead of sendmail.

"..You can see the form I´m talking about in:  .."

i went to the URL you posted above & saw the form at that page.

Here is what i have understood so far.
 
* You have a HTML form using which a user can upload a file.
* Along with the file the user will provide a bunch of other information.

After this i am not sure what exactly you want to do.

Please explain, in plain english in a setp-by-step manner what should happen when the user provides all the info and clicks on the "Enviar" button.

Let me know.
0
 

Author Comment

by:nadiassdcg
Comment Utility
well in plain english (although not my native tongue in case I misspelled something) if the user filled all the required fields in the form, I want to:

1.-Get an e-mail with the info (including the atachment)

2.-Send an e-mail to the user telling him that we've received his info and will contact him soon
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

".. I want to:

                     1.-Get an e-mail with the info (including the atachment)

                     2.-Send an e-mail to the user telling him that we've received his info and will contact him soon ..."

Aha!! So your requirements are much much more than just file upload. The script you have posted earlier needs to be modified, to make it work per your requirements. In fact i would recommend that we re-write the script from scratch, as it will be faster to develop, shorter in size and exactly per your specifications.

Let me know if you want to go for the re-write from scratch option.
0
 

Author Comment

by:nadiassdcg
Comment Utility
ok, I think starting from scratch would be much better than trying to fix the other script

what´s the next step?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

".. I think starting from scratch would be much .."

Excellent!!!

"..what´s the next step? .."

Is it possible for you to give me temporary access to your cgi-bin directory on hypermart?

i can then create, test and post the script for you there. While i can do the same on my server, i do not have the same directory structure and email agent as on hypermart.

If your answer is "YES", then pl. post an email id where i can contact you & i will send you an email.

Let me know.
0
 

Author Comment

by:nadiassdcg
Comment Utility
yeaph

sounds great!!!

you can contact me at vantha@prodigy.net.mx
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..sounds great!!!.."

Got it!!

Emails on the way....
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

As the first step i have extracted the HTML portion of the file and kept it in a seperate file.

You can check this file at...
http://selectivedirectory.hypermart.net/htm/nadia.html

Let me know if all looks ok & i will start work on the basic script.
0
 

Author Comment

by:nadiassdcg
Comment Utility
looks ok maneshr

sorry about the delay couldn't connect earlier
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..looks ok maneshr."

Super!!! Thanks for confirming that.

i have already started working on the basic script.

A quick question. On the HTML form, are the fields that are marked with * mandatory?
If not, then can you please tell me what fields MUST be provided by a user filling the form?

Also, we will keep in touch over EE using this question & use email only if EE is down, or if we want to exchange username/password or other such info.
0
 

Author Comment

by:nadiassdcg
Comment Utility
ok, just in case EE is down

and yes all the required fields are marked with a *
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..ok, just in case EE is down

                     and yes all the required fields are marked with a * ."


Super!! Thanks for confirming that.
0
 

Author Comment

by:nadiassdcg
Comment Utility
your welcome

then tou have all the information you need?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..then tou have all the information you need?.."

Yes. i do.

i have been a bit busy today & should be able to get to your script later in the day today.

I will keep you updated on the progress of this script.
0
 

Author Comment

by:nadiassdcg
Comment Utility
ok, thanks a lot
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:nadiassdcg
Comment Utility
maneshr,

hope you don´t mind me asking, but ... how's the script progressing?
I woudn´t botter you but I need to set a date on the delivery of this project
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..but I need to set a date on the delivery of this project .."

i can understand.

i should have the basic version ready for you before end of day (PST) tomorrow.

After we have verified the script we can go to the final version before end of day Tue.
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

i have completed work on the final script.

i have tested the script and 2 emails were sent to the email id vantha@prodigy.net.mx
Both these emails have an attachment in them

Also, an email was sent to the user submitting the form.

Finally, i have put in checks to ensure all mandatory fields are entered.

The URL to test is....
http://selectivedirectory.hypermart.net/htm/nadia.html

Let me know how this script works for you.
0
 

Author Comment

by:nadiassdcg
Comment Utility
maneshr

the script works perfectly!

: )


0
 

Author Comment

by:nadiassdcg
Comment Utility
got a question though, how do you set the mandatory fields?

in case not all the forms have the same fields
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..the script works perfectly!.."

Excellent!!! Glad to know the script works for you.


".., how do you set the mandatory fields?.."

Good question.

The key to this lies in the following line...

next if /^cp$/;     ##     Ignore this optional field.

Here i am ingorning any optional fields.

in case you have more such fields you can add more such lines.
Its as simple as that!!

Hope that helps.
0
 

Author Comment

by:nadiassdcg
Comment Utility
"next if /^cp$/;     ##     Ignore this optional field.
     if (!($$_)){     ##     Check if any of the mandatory fields are empty."

sorry, I´don´t understand, would you mind explaining it to me?

I think you are telling me that you didn't set the mandatory but the optional fields, but I don´t get how to do it.
0
 

Author Comment

by:nadiassdcg
Comment Utility
another question ... if I wanted to include an image (say the logo) in the body of the autoreply message to the user would it be to complicated?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..sorry, I´don´t understand, would you mind explaining it to me?

I think you are telling me that you didn't set the mandatory but the optional fields, but I don´t get how to do it. ..."

Sure.

next if /^cp$/;     ##     Ignore this optional field.
if (!($$_)){     ##     Check if any of the mandatory fields are empty."

Lets say your form has 10 fields in it, of which 1 is optional.

The next statement will ensure that this optional field is ignored for the empty validation.
The if statement will check if the mandatory field is empty or not.

If the mandatiry field is empty, it will show an error message.

Hope that helps.

"..r would it be to complicated?.."

No it would not be complicated, but would take some more time and effort in adding the code, testing it & then installing it on your hypermart server.

0
 

Author Comment

by:nadiassdcg
Comment Utility
ok then, the image in the reply mail isn't necessary, so I'll skip it

the fields aren't still cristal clear for me, for what I understood, if I have a option field named celular, I would type:

next if /^cp$celular/;

is that ok?
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

".. if I have a option field named  celular, I would type:.."

"..is that ok? ..."

No. If you have a field called celular that you want to make optional then you just add the following new line

next if /^celular$/;

So you final set of statements will look like....

next if /^cp$/;
next if /^celular$/;

if (!($$_)){     ##     Check if any of the mandatory fields are empty.

Hope that clarifies things.
0
 

Author Comment

by:nadiassdcg
Comment Utility
and if that´s ok, how would I set multiple optional fields?, like this:

next if /^cp$celular, $CP, $tel_oficina/;
0
 

Author Comment

by:nadiassdcg
Comment Utility
ahh!
so it shuld look like this:

next if /^cp$/;
next if /^celular$/;
next if /^CP$/;
next if /^tel_oficina$/;

0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..´s ok, how would I set multiple optional fields?, like this:..."

then you would do this..

## Ignore optional fields

if (/^cp$/ || /^celular$/ || /^tel_oficina$/){
  next;
}

HTH.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 70 total points
Comment Utility
nadiassdcg,

"..ahh!
                     so it shuld look like this:.."

YES!!! That is correct.

Either you can have 1 statement per field OR club all these fields into a single if statement (as i have shown previously)

0
 

Author Comment

by:nadiassdcg
Comment Utility
maneshr, thanks a lot

great script!!!

: )
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
nadiassdcg,

"..maneshr, thanks a lot

                     great script!!!..."

You're welcome.

Glad to know you got the solution you were looking for.

Please remember to change the password to your hypermart account ASAP.
0
 

Author Comment

by:nadiassdcg
Comment Utility
ok, I´ll change the password, a little problem though

I changed the script:

if (/^cp$/ || /^celular$/ || /^tel_oficina$/||/^extension$/|| /^dia_hora_entrega$/){
 next;     ##     Ignore this optional field.

and I get an error:

Execution of /home/cgi-bin/head_hunters1.pl aborted due to compilation errors.
Missing right curly or square bracket at /home/cgi-bin/head_hunters1.pl line 129, at end of line
syntax error at /home/cgi-bin/head_hunters1.pl line 129, at EOF
Execution of /home/cgi-bin/head_hunters1.pl aborted due to compilation errors.
0
 

Author Comment

by:nadiassdcg
Comment Utility
and if I set them like:

next if /^cp$/;
next if /^celular$/;
next if /^CP$/;
next if /^tel_oficina$/;

it doesn´t send an error, and it doesn´t ask for the field to be filled, but if I fill it doesn´t send the information
0
 

Author Comment

by:nadiassdcg
Comment Utility
the script with the changes is headhunters1.pl
0
 

Author Comment

by:nadiassdcg
Comment Utility
0
 

Author Comment

by:nadiassdcg
Comment Utility
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now