Hi,
I would like to have the following routine save the attachment under "username.ext"
.ext should have to be extracted from $in{'FILE_NAME'}. But how?
The following 2 lines extract name.ext from c:/dir/subdir/name.ext, but I only need .ext!
($filename =~ m,[/\\]([^/\\] )$,) and ($filename = $1);
My whole sub: (If your curious)
if ($in{'FILE_CONTENT'}) {
if (length($in{'FILE_CONTENT'}) > 300000) {
&site_html_request_error ("printenv: Maximum attachment size is 300kb. Please email with attachment.");
return;
}
if ($in{'FILE_NAME'} !~ /\.doc$|\.rtf$|\.txt$/i) {
&site_html_request_error ("printenv: Only files with the following extension(s) are allowed: .doc, .rtf and .txt");
return;
}
my $file_id = $in{$db_key};
my $attachment_name = $in{$db_cols[$db_attachment_name]};
$attachment_name =~ s/ä/ae/g;
$attachment_name =~ s/ö/oe/g;
$attachment_name =~ s/ü/ue/g;
$attachment_name =~ s/ë/e/g;
open (FILE, ">/users/www/data/attachments/$file_id-$attachment_name") or &cgierr ("Can't save attach: $file_id-$attachment_name. Reason: $!");
print FILE $in{'FILE_CONTENT'};
close FILE;
}
I would like to have the following routine save the attachment under "username.ext"
.ext should have to be extracted from $in{'FILE_NAME'}. But how?
The following 2 lines extract name.ext from c:/dir/subdir/name.ext, but I only need .ext!
Code:
my $filename = $in{'FILE_NAME'}; ($filename =~ m,[/\\]([^/\\] )$,) and ($filename = $1);
My whole sub: (If your curious)
Code:
# Save any attachments if ($in{'FILE_CONTENT'}) {
if (length($in{'FILE_CONTENT'}) > 300000) {
&site_html_request_error ("printenv: Maximum attachment size is 300kb. Please email with attachment.");
return;
}
if ($in{'FILE_NAME'} !~ /\.doc$|\.rtf$|\.txt$/i) {
&site_html_request_error ("printenv: Only files with the following extension(s) are allowed: .doc, .rtf and .txt");
return;
}
my $file_id = $in{$db_key};
my $attachment_name = $in{$db_cols[$db_attachment_name]};
$attachment_name =~ s/ä/ae/g;
$attachment_name =~ s/ö/oe/g;
$attachment_name =~ s/ü/ue/g;
$attachment_name =~ s/ë/e/g;
open (FILE, ">/users/www/data/attachments/$file_id-$attachment_name") or &cgierr ("Can't save attach: $file_id-$attachment_name. Reason: $!");
print FILE $in{'FILE_CONTENT'};
close FILE;
}