I built a form to allow attachments. I can upload the file successfully and I can send the email with the attachments successfully. The files have content there are no issues with that.</p.

My issue is with the file name. When the file name is uploaded it includes the entire path but without "/" so it's not parsing correctly when I use "fileparse"

EXAMPLE: When I send the file the file name ends up being C_Documents and SettingsrytremblMyDocuments9000_dollar_check_image.pdf

See the name runs together. Here is my code

sub openattachment { my $Buffer; my $BytesRead; my $Size = 0; my $FileLimit = 1024000; $theirFile = $attachmentFiles[$i]; $FileName = $attachmentFiles[$i]; my $tmpDir = "/tmp"; my $date_stamp; my $fileCount = $i + 1 ; #Get the date to stamp on the file &getDateAndTime; $date_stamp = "$mon$mday$year"."_"."$hour"."hr"."$min"."min"."$sec +"; # Parse FileName to remove path my ($name,$path,$extension) = fileparse($FileName,'\..*'); $FileName = $name . $extension; # Replace blank spaces with underscores #$FileName =~ s/\s/_/g; # Remove non safe characters #$FileName =~ s/[^a-zA-Z0-9_.-\\]//g; # Create temporary directory if it doesn't exist if ( ! -d "$tmpDir" ) { mkdir "$tmpDir"; chmod 0777,"$tmpDir"; } # Delete file if it exists if ( -r "$tmpDir/$FileName" ) { unlink "$tmpDir/$FileName"; } open(OUTPUT,">$tmpDir/$FileName"); while ($BytesRead = read($theirFile,$Buffer,1024)) { print OUTPUT $Buffer; $Size += $BytesRead; if ($Size > $FileLimit) { &error_message("Your file is over the file size limit."); close (OUTPUT); unlink "$tmpDir/$FileName"; $theirName = "NULL"; } } $myFilePath = "$tmpDir/$FileName"; close(OUTPUT); chmod 0666,"$tmpDir/$FileName"; }

In reply to 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.