rrtrems has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FileParse is NOT working correctly
by almut (Canon) on Apr 20, 2009 at 18:40 UTC | |
by rrtrems (Initiate) on Apr 20, 2009 at 23:53 UTC | |
|
Re: FileParse is NOT working correctly
by ELISHEVA (Prior) on Apr 20, 2009 at 18:40 UTC | |
by rrtrems (Initiate) on Apr 20, 2009 at 20:01 UTC | |
by almut (Canon) on Apr 20, 2009 at 21:00 UTC | |
|
Re: FileParse is NOT working correctly
by afoken (Chancellor) on Apr 20, 2009 at 22:53 UTC | |
by rrtrems (Initiate) on Apr 21, 2009 at 01:00 UTC | |
by afoken (Chancellor) on Apr 21, 2009 at 13:39 UTC | |
by rrtrems (Initiate) on Apr 21, 2009 at 13:53 UTC | |
by Anonymous Monk on Apr 21, 2009 at 14:03 UTC |