This is part of a huge form processing CGI. Nothing comes from command lines, everything comes from form input.

Here is the code that retrieves the file from the form and the email that sends the attachment. The file name appears to have underscores after it is retrieved from the form for some reason????

# ADD ATTACHMENTS TO FORM # Set the attachment variables my $FileName; my $FileName2; my $FileName3; my $myFilePath; my $i; my @attachmentFiles; # Get the attachment $FileName = $query->param('FileName'); $FileName2 = $query->param('FileName2'); $FileName3 = $query->param('FileName3'); @attachmentFiles = (); # Put the attachments in an Array # This allows each file to be filtered through read and attached if( !defined($FileName) || $FileName ne "") { push (@attachmentFiles, $FileName); if( !defined($FileName2) || $FileName2 ne "") { push (@attachmentFiles, $FileName2); if( !defined($FileName3) || $FileName3 ne "") { push (@attachmentFiles, $FileName3); } } }

This pulls in the values from the form. There are three attachment fields so they get pushed to an array, but this problem has been there from the get go when there was only 1 file. My first thought was to simply rename the file with a time stamp, but I would rather retain the name of the file they uploaded.

Here is the code that attaches it to the email. I had worked on this for months and don't understand why the path is being altered so that I can't get the file name easily.

sub admin_mailer { print DEBUG "in admin mailer...\n" if ($debug_log); $admin = $query->param('admin'); # If $email begins "test:" then we are in a test mode. Send # the admin e-mail to the specified e-mail address. if ( $email =~ /^test:/ ) { $email =~ s/^test\://; $admin = $email; } @sendary = split ( /,/, $admin ); if ( $query->param('admin_subject') ) { $subj = convertInputString( $query->param('admin_subject') ); } else { $subj = convertInputString( $query->param('subject') ); } print DEBUG "Admin mailer converting...\n"; my $email = convertInputString( $query->param('EMail') ); my $fname = convertInputString( $query->param('FirstName') ); my $lname = convertInputString( $query->param('LastName') ); my $from = $fname . " " . $lname . " <" . $email . ">"; # # Give the e-mail client a hint of what charset to # expect. Some clients may ignore but at least we # try to behave nicely. # #&logEvent("Mailing admins @sendary From: $fname $lname"); #open( MAIL, "|$MAILPROG @sendary" ) or die "Cannot open $MAILPROG +: $!"; #print MAIL "MIME-Version: 1.0\n"; #if ( $inputCharset =~ /UTF\-8/i ) { # print DEBUG "Formatting Mail UTF-8\n" if ($debug_log); # print MAIL "Content-type: text/plain; charset=UTF-8\n"; #} #else { # print DEBUG "Formatting Mail ISO-8859-1\n" if ($debug_log); # print MAIL "Content-type: text/plain; charset=ISO-8859-1\n"; #} #print MAIL "Content-type: text/plain; charset=" . $outputCharset +. "; \n"; #print MAIL "From: \"$fname $lname\"<$email>\n"; #print MAIL "To: $admin\n"; #print MAIL "Subject: $subj \n"; #print MAIL "\n"; #print MAIL ""; @names = $query->param; @namelist = split ( /,/, $query->param(admin_mailer_fields) ); print DEBUG "namelist : @namelist\n"; if (@namelist) { # Go through the form hash from loadFormHash and get the d +esired fields in the order of # admin_mailer_values foreach $name (@namelist) { $message_body = $message_body . $name . ": " . $HASH{$ +name} . "\n\n"; } } else { foreach $record ( keys(%HASH) ) { $message_body = $message_body . $record . ": " . +$HASH{$record} . "\n\n"; } } ### Create the multipart container $msg = MIME::Lite->new ( From => $from, To => $admin, Subject => $subj, Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; ### Add the text message part $msg->attach ( Type => 'TEXT', Data => $message_body ) or die "Error adding the text message part: $!\n"; ### Add the file if(@attachmentFiles ne "" || @attachmentFiles ne "NULL"){ for ( $i = 0 ; $i < scalar ( @attachmentFiles ) ; $i++ ) { &openattachment; if($theirFile ne "NULL" || $theirFile ne "" ){ $msg->attach ( Type => 'AUTO', Path => $myFilePath, FileName => $FileName, Disposition => 'attachment' ); } } } ### Send the Message $msg->send; }

In reply to Re^2: FileParse is NOT working correctly by rrtrems
in thread FileParse is NOT working correctly by rrtrems

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.