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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |