OSDN Git Service

(no commit message)
[fswiki/fswiki-lite.git] / download.cgi
diff --git a/download.cgi b/download.cgi
new file mode 100644 (file)
index 0000000..5729e87
--- /dev/null
@@ -0,0 +1,73 @@
+#!/usr/bin/perl\r
+################################################################################\r
+#\r
+# FSWiki Lite - ÅºÉÕ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤¿¤á¤ÎCGI¥¹¥¯¥ê¥×¥È\r
+#\r
+################################################################################\r
+require "./lib/common.pl";\r
+#==============================================================================\r
+# ¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë\r
+#==============================================================================\r
+&ReadParse();\r
+my $page = $in{"p"};\r
+my $file = $in{"f"};\r
+\r
+#==============================================================================\r
+# ¥¨¥é¡¼¥Á¥§¥Ã¥¯\r
+#==============================================================================\r
+if($page eq ""){\r
+       &Util::error("¥Ú¡¼¥¸¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");\r
+}\r
+if($file eq ""){\r
+       &Util::error("¥Õ¥¡¥¤¥ë¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");\r
+}\r
+#==============================================================================\r
+# ¥À¥¦¥ó¥í¡¼¥É\r
+#==============================================================================\r
+my $filename = sprintf("$main::ATTACH_DIR/%s.%s",&Util::url_encode($page),&Util::url_encode($file));\r
+unless(-e $filename){\r
+       &Util::error("»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¸ºß¤·¤Þ¤»¤ó¡£");\r
+}\r
+\r
+my $contenttype = &get_mime_type($file);\r
+my $ua = $ENV{"HTTP_USER_AGENT"};\r
+my $disposition = ($contenttype =~ /^image\// && $ua !~ /MSIE/ ? "inline" : "attachment");\r
+\r
+&jcode::convert(\$file,'sjis');\r
+\r
+print "Content-Type: $contenttype\n";\r
+print "Content-Disposition: $disposition;filename=\"$file\"\n\n";\r
+open(DATA,$filename);\r
+binmode(DATA);\r
+while(<DATA>){\r
+       print $_;\r
+}\r
+close(DATA);\r
+\r
+\r
+#==============================================================================\r
+# MIME¥¿¥¤¥×¤ò¼èÆÀ¤·¤Þ¤¹\r
+#==============================================================================\r
+sub get_mime_type {\r
+       my $file  = shift;\r
+       my $type  = lc(substr($file,rindex($file,".")));\r
+       my $ctype;\r
+       \r
+       if   ($type eq ".gif" ){ $ctype = "image/gif"; }\r
+       elsif($type eq ".txt" ){ $ctype = "text/plain"; }\r
+       elsif($type eq ".rb"  ){ $ctype = "text/plain"; }\r
+       elsif($type eq ".pl"  ){ $ctype = "text/plain"; }\r
+       elsif($type eq ".java"){ $ctype = "text/plain"; }\r
+#      elsif($type eq ".html"){ $ctype = "text/html"; }\r
+#      elsif($type eq ".htm" ){ $ctype = "text/html"; }\r
+       elsif($type eq ".css" ){ $ctype = "text/css"; }\r
+       elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; }\r
+       elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; }\r
+       elsif($type eq ".png" ){ $ctype = "image/png"; }\r
+       elsif($type eq ".bmp" ){ $ctype = "image/bmp"; }\r
+       elsif($type eq ".doc" ){ $ctype = "application/msword"; }\r
+       elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; }\r
+       else                   { $ctype = "application/octet-stream"; }\r
+       \r
+       return $ctype;\r
+}\r