OSDN Git Service

BugTrack-wiki/353 : 番号付きリスト項目リストの組合せが正しく表示されない
[fswiki/fswiki-lite.git] / download.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # FSWiki Lite - ÅºÉÕ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤¿¤á¤ÎCGI¥¹¥¯¥ê¥×¥È
5 #
6 ################################################################################
7 require "./lib/common.pl";
8 #==============================================================================
9 # ¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë
10 #==============================================================================
11 &ReadParse();
12 my $page = $in{"p"};
13 my $file = $in{"f"};
14
15 #==============================================================================
16 # ¥¨¥é¡¼¥Á¥§¥Ã¥¯
17 #==============================================================================
18 if($page eq ""){
19         &Util::error("¥Ú¡¼¥¸¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
20 }
21 if($file eq ""){
22         &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
23 }
24 #==============================================================================
25 # ¥À¥¦¥ó¥í¡¼¥É
26 #==============================================================================
27 my $filename = sprintf("$main::ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file));
28 unless(-e $filename){
29         &Util::error("»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¸ºß¤·¤Þ¤»¤ó¡£");
30 }
31
32 my $contenttype = &get_mime_type($file);
33 my $ua = $ENV{"HTTP_USER_AGENT"};
34 my $disposition = ($contenttype =~ /^image\// && $ua !~ /MSIE/ ? "inline" : "attachment");
35
36 &jcode::convert(\$file,'sjis');
37
38 print "Content-Type: $contenttype\n";
39 print "Content-Disposition: $disposition;filename=\"$file\"\n\n";
40 open(DATA,$filename);
41 binmode(DATA);
42 while(<DATA>){
43         print $_;
44 }
45 close(DATA);
46
47
48 #==============================================================================
49 # MIME¥¿¥¤¥×¤ò¼èÆÀ¤·¤Þ¤¹
50 #==============================================================================
51 sub get_mime_type {
52         my $file  = shift;
53         my $type  = lc(substr($file,rindex($file,".")));
54         my $ctype;
55         
56         if   ($type eq ".gif" ){ $ctype = "image/gif"; }
57         elsif($type eq ".txt" ){ $ctype = "text/plain"; }
58         elsif($type eq ".rb"  ){ $ctype = "text/plain"; }
59         elsif($type eq ".pl"  ){ $ctype = "text/plain"; }
60         elsif($type eq ".java"){ $ctype = "text/plain"; }
61 #       elsif($type eq ".html"){ $ctype = "text/html"; }
62 #       elsif($type eq ".htm" ){ $ctype = "text/html"; }
63         elsif($type eq ".css" ){ $ctype = "text/css"; }
64         elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; }
65         elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; }
66         elsif($type eq ".png" ){ $ctype = "image/png"; }
67         elsif($type eq ".bmp" ){ $ctype = "image/bmp"; }
68         elsif($type eq ".doc" ){ $ctype = "application/msword"; }
69         elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; }
70         else                   { $ctype = "application/octet-stream"; }
71         
72         return $ctype;
73 }