Update of /cvsroot/sandweb/sandweb/lib/SandWeb
In directory usw-pr-cvs1:/tmp/cvs-serv31266/lib/SandWeb
Modified Files:
File.pm
Log Message:
moved download/mime detection code into the download method of
File.pm
hmm, get_mime_type would make a good method too, would compliment
get_file_type nicely ( knowing what's text and what's not is very
cool, but it would be even cooler to take a guess at filetype
based on MIME type and load a different icon, or be able to take
different user-defined actions ).
Index: File.pm
===================================================================
RCS file: /cvsroot/sandweb/sandweb/lib/SandWeb/File.pm,v
retrieving revision 1.22
retrieving revision 1.23
diff -U2 -r1.22 -r1.23
--- File.pm 2001/12/20 20:29:41 1.22
+++ File.pm 2001/12/20 23:11:38 1.23
@@ -95,4 +95,39 @@
}
+sub download {
+ my $self = shift;
+ my $location = $self->{'location'};
+ my $filename = $self->{'filename'};
+ my $log = $self->{'log_obj'};
+
+ $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;
+}
+
sub create_file {
my $self = shift;
|