トップトップ 新規新規 編集編集 一覧一覧 検索検索 ヘルプヘルプ

改造/download.cgi

ダウンロードファイル名をファイルに付けられたファイル名にする

2008年7月現在配布されているFSWikiLite 0.0.11のdownload.cgiだと、ページに添付したファイルをダウンロードする際ファイル名がどれも「download.cgi」という名になってしまい不都合あるので、ちゃんとファイルに付けられたファイル名でダウンロード出来るようにする。

改造方法

 print "Content-Disposition: $disposition;filename=\"".&jcode::convert($file,'sjis')."\"\n\n";
 print "Content-Disposition: $disposition;filename=\"".$file."\"\n\n";

MIMEタイプ取得をcommon.plに移す

ファイルのMIMEタイプ取得を必要とするのはdownload.cgiだけに限らず、汎用性高いのでcommon.plのUtilに移し各種プラグインやCGIからも利用出来るようにする。

改造方法

 my $contenttype = &get_mime_type($file);
 my $contenttype = &Util::get_mime_type($file);
 #==============================================================================
 # MIMEタイプを取得します
 #==============================================================================
 sub get_mime_type {
 	my $file  = shift;
 	my $type  = lc(substr($file,rindex($file,".")));
 	my $ctype;
 	
 	if   ($type eq ".gif" ){ $ctype = "image/gif"; }
 	elsif($type eq ".txt" ){ $ctype = "text/plain"; }
 	elsif($type eq ".rb"  ){ $ctype = "text/plain"; }
 	elsif($type eq ".pl"  ){ $ctype = "text/plain"; }
 	elsif($type eq ".java"){ $ctype = "text/plain"; }
 #	elsif($type eq ".html"){ $ctype = "text/html"; }
 #	elsif($type eq ".htm" ){ $ctype = "text/html"; }
 	elsif($type eq ".css" ){ $ctype = "text/css"; }
 	elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; }
 	elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; }
 	elsif($type eq ".png" ){ $ctype = "image/png"; }
 	elsif($type eq ".bmp" ){ $ctype = "image/bmp"; }
 	elsif($type eq ".doc" ){ $ctype = "application/msword"; }
 	elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; }
 	else                   { $ctype = "application/octet-stream"; }
 	
 	return $ctype;
 }
 #===============================================================================
 # インラインプラグインをパースしてコマンドと引数に分割
 #===============================================================================
 sub parse_plugin {
 
 〜中略〜
 
 	return {command=>$cmd,args=>\@ret_args};
 }
 
 1;
 #===============================================================================
 # インラインプラグインをパースしてコマンドと引数に分割
 #===============================================================================
 sub parse_plugin {
 
 〜中略〜
 
 	return {command=>$cmd,args=>\@ret_args};
 }
 
 #==============================================================================
 # MIMEタイプを取得します
 #==============================================================================
 sub get_mime_type {
 	my $file  = shift;
 	my $type  = lc(substr($file,rindex($file,".")));
 	my $ctype;
 	
 	if   ($type eq ".gif" ){ $ctype = "image/gif"; }
 	elsif($type eq ".txt" ){ $ctype = "text/plain"; }
 	elsif($type eq ".rb"  ){ $ctype = "text/plain"; }
 	elsif($type eq ".pl"  ){ $ctype = "text/plain"; }
 	elsif($type eq ".java"){ $ctype = "text/plain"; }
 #	elsif($type eq ".html"){ $ctype = "text/html"; }
 #	elsif($type eq ".htm" ){ $ctype = "text/html"; }
 	elsif($type eq ".css" ){ $ctype = "text/css"; }
 	elsif($type eq ".jpeg"){ $ctype = "image/jpeg"; }
 	elsif($type eq ".jpg" ){ $ctype = "image/jpeg"; }
 	elsif($type eq ".png" ){ $ctype = "image/png"; }
 	elsif($type eq ".bmp" ){ $ctype = "image/bmp"; }
 	elsif($type eq ".doc" ){ $ctype = "application/msword"; }
 	elsif($type eq ".xls" ){ $ctype = "application/vnd.ms-excel"; }
 	else                   { $ctype = "application/octet-stream"; }
 	
 	return $ctype;
 }
 
 1;