From: Rob H. <for...@us...> - 2001-12-20 23:26:21
|
Update of /cvsroot/sandweb/sandweb/lib/SandWeb In directory usw-pr-cvs1:/tmp/cvs-serv3618/lib/SandWeb Modified Files: File.pm Log Message: created private method, _get_mime_type that's used by download Index: File.pm =================================================================== RCS file: /cvsroot/sandweb/sandweb/lib/SandWeb/File.pm,v retrieving revision 1.23 retrieving revision 1.24 diff -U2 -r1.23 -r1.24 --- File.pm 2001/12/20 23:11:38 1.23 +++ File.pm 2001/12/20 23:26:19 1.24 @@ -82,4 +82,28 @@ } +sub _get_mime_type { + my %args = @_; + my $location = $args{'location'}; + my $filename = $args{'filename'}; + + my @file_split = split(/\./, $filename); + my $file_extension = $file_split[$#file_split]; + my $mime_type; + open FILE,"< /usr/local/apache/conf/mime.types"; + my @mimes = <FILE>; + close FILE; + foreach my $entry (@mimes) { + unless ( $entry =~ /^#/) { + my @mime_string = split(/\s+/, $entry); + if ($mime_string[1]) { + if ( $file_extension eq $mime_string[1] ){ + $mime_type = $mime_string[0]; + } + } + } + } + return $mime_type; +} + sub get_size { my $self = shift; @@ -103,29 +127,19 @@ $log->debug("downloading file : $location/$filename"); open FILE,"< $users_dir/$username/$location/$filename"; - my @file = <FILE>; - close FILE; - my @file_split = split(/\./, $filename); - my $file_extension = $file_split[$#file_split]; - my $content_type; - open FILE,"< /usr/local/apache/conf/mime.types"; - my @mimes = <FILE>; - close FILE; - foreach my $mime_type (@mimes) { - unless ( $mime_type =~ /^#/) { - my @mime_string = split(/\s+/, $mime_type); - if ($mime_string[1]) { - if ( $file_extension eq $mime_string[1] ){ $content_type = $mime_string[0]; - } - } - } - } - unless ($content_type) { - $content_type = "binary/unknown"; - } - print "content-type:$content_type\n\n"; - foreach my $line (@file) { - print "$line"; - } - exit 0; + + my $mime_type = _get_mime_type( + 'location' => "$location", + 'filename' => "$filename", + ); + $log->debug("MIME type looks like : $mime_type"); + + unless ($mime_type) { + $mime_type = "binary/unknown"; + } + + print "content-type:$mime_type\n\n"; + foreach my $line (@file) { + print "$line"; + } } |