で表示した際はいちいちブラウザの「戻る」ボタンでお戻りください。
また、ダウンロードした資料、写真などについては、著作権、プライバシー等にご配慮の上お使いください。'; $Title4 = ''; // 下段apacheロゴ前に表示。 $ResumeOption = TRUE; // 中断・再開、部分ダウンロードの対応。TRUEでする、FALSEでしない。動作を充分確認していないので安全を期するならFALSEに。 // ファイル情報一覧。独自のもあるようで必ずしも最適ではないかも。なんとWindowsとMacで同じ拡張子で中身がちがうのがある! // iconはapache標準のものをそのまま使います。httpd.confの/icons/エイリアスにアイコンフォルダが指定されている必要があります。 $FileInfo = array( // '' => array('icon' => '', 'type' => '', 'info' => ''), // とりあえずよく使うものだけ。 'avi' => array('icon' => 'movie.gif', 'type' => 'video/msvideo', 'info' => 'Windows Aviフォーマット動画'), 'bmp' => array('icon' => 'image2.gif', 'type' => 'image/bmp', 'info' => 'ビットマップ形式画像'), 'css' => array('icon' => 'text.gif', 'type' => 'text/css', 'info' => 'カスケーディングスタイルシート'), 'doc' => array('icon' => 'layout.gif', 'type' => 'application/msword', 'info' => 'Microsoft Word 書類'), 'docx' => array('icon' => 'layout.gif', 'type' => 'application/msword', 'info' => 'Microsoft Word 書類'), 'gif' => array('icon' => 'image2.gif', 'type' => 'image/gif', 'info' => 'GIF形式画像'), 'gz' => array('icon' => 'compressed.gif', 'type' => 'application/x-tar', 'info' => 'Tar圧縮ファイル'), 'htm' => array('icon' => 'layout.gif', 'type' => 'text/html', 'info' => 'HTML Web Page'), 'html' => array('icon' => 'layout.gif', 'type' => 'text/html', 'info' => 'HTML Web Page'), 'ico' => array('icon' => 'image2.gif', 'type' => 'image/x-ico', 'info' => 'ビットマップ形式アイコン画像'), 'jpg' => array('icon' => 'image2.gif', 'type' => 'image/jpeg', 'info' => 'JPEG形式画像'), 'jpeg' => array('icon' => 'image2.gif', 'type' => 'image/jpeg', 'info' => 'JPEG形式画像'), 'js' => array('icon' => 'text.gif', 'type' => 'text/plain', 'info' => 'JavaScriptソース'), 'log' => array('icon' => 'text.gif', 'type' => 'text/plain', 'info' => 'ログファイル'), 'lzh' => array('icon' => 'compressed.gif', 'type' => 'application/lha', 'info' => 'LHA形式圧縮ファイル'), 'mid' => array('icon' => 'sound2.gif', 'type' => 'audio/x-midi', 'info' => 'MIDI音楽ファイル'), 'mov' => array('icon' => 'movie.gif', 'type' => 'video/mov', 'info' => 'Quicktime動画'), 'm3u' => array('icon' => 'sound2.gif', 'type' => 'text/plain', 'info' => 'MP3再生リスト'), 'mp3' => array('icon' => 'sound2.gif', 'type' => 'audio/mp3', 'info' => 'MP3形式音楽ファイル'), 'mp4' => array('icon' => 'movie.gif', 'type' => 'video/mp4', 'info' => 'MP4形式動画'), 'mpeg' => array('icon' => 'movie.gif', 'type' => 'video/mpeg', 'info' => 'MPEG形式動画'), 'mpg' => array('icon' => 'movie.gif', 'type' => 'video/mpeg', 'info' => 'MPEG形式動画'), 'pdf' => array('icon' => 'pdf.gif', 'type' => 'application/pdf', 'info' => 'PDFファイル'), 'php' => array('icon' => 'p.gif', 'type' => 'text/plain', 'info' => 'PHPスクリプト'), 'pl' => array('icon' => 'p.gif', 'type' => 'text/plain', 'info' => 'Perlスクリプト'), 'png' => array('icon' => 'image2.gif', 'type' => 'image/png', 'info' => 'PNG形式画像'), 'sh' => array('icon' => 'script.gif', 'type' => 'text/plain', 'info' => 'シェルスクリプト'), 'tar' => array('icon' => 'compressed.gif', 'type' => 'application/x-tar', 'info' => 'TAR形式書庫ファイル'), 'tgz' => array('icon' => 'compressed.gif', 'type' => 'application/x-tar', 'info' => 'TAR形式圧縮書庫ファイル'), 'tif' => array('icon' => 'image2.gif', 'type' => 'image/tiff', 'info' => 'TIFF形式画像'), 'txt' => array('icon' => 'text.gif', 'type' => 'text/plain', 'info' => '一般的なテキスト文書'), 'wav' => array('icon' => 'sound1.gif', 'type' => 'audio/x-wav', 'info' => 'WAVE形式サウンド'), 'wma' => array('icon' => 'sound1.gif', 'type' => 'audio/x-ms-wma', 'info' => 'Windows Media Audioファイル'), 'wmv' => array('icon' => 'movie.gif', 'type' => 'video/msvideo', 'info' => 'Windows Media Videoファイル'), 'xls' => array('icon' => 'layout.gif', 'type' => 'application/vnd.ms-excel', 'info' => 'Microsoft Excel 書類'), 'xlsx' => array('icon' => 'layout.gif', 'type' => 'application/vnd.ms-excel', 'info' => 'Microsoft Excel 書類'), 'zip' => array('icon' => 'compressed.gif', 'type' => 'application/zip', 'info' => 'ZIP形式圧縮ファイル'), /* 'ai' => array('icon' => 'ps.gif', 'type' => 'application/postscript', 'info' => 'Adobe Illustrator Document'), 'asp' => array('icon' => 'script.gif', 'type' => 'text/plain', 'info' => 'ASP Script'), 'aspx' => array('icon' => 'script.gif', 'type' => 'text/plain', 'info' => 'ASP.NET Script'), 'bin' => array('icon' => 'binary.gif', 'type' => 'application/octet-stream', 'info' => 'Binary Data'), 'bm' => array('icon' => 'image2.gif', 'type' => 'image/bmp', 'info' => 'Bitmap Image'), 'c' => array('icon' => 'c.gif', 'type' => 'text/plain', 'info' => 'C Source'), 'cpp' => array('icon' => 'c.gif', 'type' => 'text/plain', 'info' => 'CPP Source'), 'divx' => array('icon' => 'movie.gif', 'type' => 'video/divx', 'info' => 'Video Divx'), 'dll' => array('icon' => 'binary.gif', 'type' => 'application/octet-stream', 'info' => 'Dynamic link library'), 'eps' => array('icon' => 'ps.gif', 'type' => 'application/postscript', 'info' => 'Encapsulated PostScript'), 'exe' => array('icon' => 'binary.gif', 'type' => 'application/octet-stream', 'info' => 'Windows Executable'), 'fla' => array('icon' => 'image3.gif', 'type' => 'application/x-flash', 'info' => 'Flash Document'), 'flv' => array('icon' => 'movie.gif', 'type' => 'video/flash', 'info' => 'Flash Video'), 'indd' => array('icon' => 'ps.gif', 'type' => 'application/postscript', 'info' => 'Indesign Document'), 'iso' => array('icon' => 'diskimg.gif', 'type' => 'application/octet-stream', 'info' => 'Disk Image'), 'java' => array('icon' => 'text.gif', 'type' => 'text/plain', 'info' => 'Java Source'), 'odb' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.database', 'info' => 'Oasis database'), 'odf' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.formula', 'info' => 'Oasis form'), 'odg' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.graphics', 'info' => 'Oasis graphics'), 'odp' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.presentation','info' => 'Oasis presentation'), 'ods' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.spreadsheet', 'info' => 'Oasis spreadsheet'), 'odt' => array('icon' => 'generic.gif', 'type' => 'application/vnd.oasis.opendocument.text', 'info' => 'Oasis text'), 'ogg' => array('icon' => 'box1.gif', 'type' => 'application/ogg', 'info' => 'Ogg media container'), 'otf' => array('icon' => 'a.gif', 'type' => 'application/x-font-TrueType', 'info' => 'OpenType Font'), 'ppt' => array('icon' => 'image3.gif', 'type' => 'application/vnd.ms-powerpoint', 'info' => 'Powerpoint Presentation'), 'pptx' => array('icon' => 'image3.gif', 'type' => 'application/vnd.ms-powerpoint', 'info' => 'Powerpoint Presentation'), 'ps' => array('icon' => 'ps.gif', 'type' => 'application/postscript', 'info' => 'PostScript'), 'psd' => array('icon' => 'image3.gif', 'type' => 'x-vnd.adobe.photoshop', 'info' => 'Photoshop Image'), 'qt' => array('icon' => 'movie.gif', 'type' => 'video/quicktime', 'info' => 'Quicktime Video'), 'ra' => array('icon' => 'sound1.gif', 'type' => 'audio/vnd.rn-realaudio', 'info' => 'RealAudio'), 'rar' => array('icon' => 'compressed.gif', 'type' => 'application/zip', 'info' => 'Rar Archive'), 'rss' => array('icon' => 'generic.gif', 'type' => 'text/xml', 'info' => 'RSS'), 'rtf' => array('icon' => 'layout.gif', 'type' => 'application/rtf', 'info' => 'Rich Text File'), 'smil' => array('icon' => 'image3.gif', 'type' => 'application/smil', 'info' => 'Synchronized Multimedia Integration Language'), 'sql' => array('icon' => 'box2.gif', 'type' => 'text/plain', 'info' => 'SQL'), 'swf' => array('icon' => 'movie.gif', 'type' => 'application/x-shockwave-flash', 'info' => 'Flash Animation'), 'tex' => array('icon' => 'tex.gif', 'type' => 'application/x-tex', 'info' => 'TeX File'), 'tmp' => array('icon' => 'unknown.gif', 'type' => 'application/octet-stream', 'info' => 'Temporary file'), 'ttf' => array('icon' => 'a.gif', 'type' => 'application/x-font-TrueType', 'info' => 'TrueType Font'), 'url' => array('icon' => 'world1.gif', 'type' => 'text/plain', 'info' => 'URL'), 'xml' => array('icon' => 'layout.gif', 'type' => 'text/xml', 'info' => 'XML Document'), */ ); function showindex($dirpath) { global $Encoding, $Title2, $Title3, $Title4; $rootdir = mb_ereg_replace('/[^/]*$', '/', $_SERVER['SCRIPT_NAME']); $Title1 = 'Index of http://'.$_SERVER['SERVER_NAME'].$rootdir.($dirpath ? "?dir=$dirpath" : ''); echo(' '.$Title1.'

'.$Title1.'

'.$Title2.'

'.$Title3.'

'); echo(' '); echo(' '); if($dirpath) { $parent_dir = mb_ereg_replace('/?[^/]*$', '', $dirpath); echo(' '); } else { echo(' '); } echo(' '); $filelist_array = dir_scan($dirpath); foreach($filelist_array as $filename) { if($filename[0] == '.'){ continue; } // "."で始まる.htaccessや.htpasswdなどはセキュリティー上表示しない。 // if($filename[0] == '.' || $filename == 'index.php'){ continue; } // 自分自身も表示しないならこちら。 // if($filename[0] == '.' || $filename == 'index.php' || mb_eregi('^!.*\.txt$', $filename)){ continue; } // さらに案内ファイルも表示しないなら。 $filepath = ($dirpath ? $dirpath.'/' : '').$filename; if(is_readable($filepath)) { if(is_dir($filepath)) { echo(' '); } elseif(is_file($filepath)) { echo(' '); // プレビューアイコンとリンク $viewlink = ''; if(mb_ereg('text/', contenttype($filename))) { $viewlink = ''; } elseif(mb_ereg('image/', contenttype($filename))) { $viewlink = ''; } echo(' '); echo(' '); } } } echo(' '); if($dirpath) { $parent_dir = mb_ereg_replace('/?[^/]*$', '', $dirpath); echo(' '); } else { echo(' '); } echo(' '); echo('
Name(→Download) View Last modified Size Description

Parent DirectoryParent Directory -
'.$filename.' '.date('Y-m-d H:i', filemtime($filepath)).' - '.description($filepath, 1).'
'.$filename.''.$viewlink.''.date('Y-m-d H:i', filemtime($filepath)).' '.number_format(filesize($filepath)).' '.description($filepath, 1).'
Parent DirectoryParent Directory -

'); echo(" $Title4"); echo('
'); echo(' '); } // $dirにあるファイル及びディレクトリの名前をリストする。 function dir_scan($dir) { if(empty($dir)){ $dir = '.'; } if(!file_exists($dir) || !is_dir($dir) || !($dir_obj=dir($dir))){ return NULL; } $filelist_array = array(); while(($filename = ($dir_obj->read())) !== FALSE) { if($filename[0] != '.'){ $filelist_array[] = $filename; } } sort($filelist_array); return($filelist_array); } // パスからファイル名を得る。basename()は日本語では動作しない。有名なバグ。 function filename($path) { return(mb_ereg_replace('^.*/([^/]+)/*$', '\1', $path)); } // ファイル拡張子から表示するアイコンを決定。httpサーバーapacheのをそのまま使う。 function fileicon($filename) { global $FileInfo; // 頭が"!"のテキストファイルは特別扱い。ファイルの案内等に使う。アイコンも変えておく。 if(mb_eregi('^!.*\.txt$', $filename)) { // お好きなやつで。 // return('alert.black.gif'); // return('alert.red.gif'); return('hand.right.gif'); } // pathinfo()を使うと.extensionがない場合エラー(Notice)が出力されるので使わない。 $extension = mb_ereg('[^\.]+\.(\w+)$', $filename, $regs) ? strtolower($regs[1]) : ''; if($extension && isset($FileInfo[$extension])){ return($FileInfo[$extension]['icon']); } return('unknown.gif'); } // 拡張子からcontent-typeを決定。 function contenttype($filename) { global $FileInfo; $extension = mb_ereg('[^\.]+\.(\w+)$', $filename, $regs) ? strtolower($regs[1]) : ''; if($extension && isset($FileInfo[$extension])){ return($FileInfo[$extension]['type']); } return(''); } // ファイルの説明。 function description($filepath, $stage=1) { global $FileInfo; static $fileinfo_txt = false; $dirpath = dirname($filepath); $filename = filename($filepath); if($fileinfo_txt === false) // 読み込んでなければ読み込む。 { if(is_readable('!FILEINFO.txt')){ $fileinfo_txt = file_get_contents('!FILEINFO.txt'); } // リストに表示する場合。 elseif(is_readable('.FILEINFO.txt')){ $fileinfo_txt = file_get_contents('.FILEINFO.txt'); } // リストに表示しない場合。 else { $fileinfo_txt = null; } } if($stage == 1) { if($fileinfo_txt) // まずは$fileinfo_txtがあればそれを検索。 { // あればそれを取得。 if(mb_ereg('(?:^|\n)(?:'.quotemeta($dirpath).'/)?'.quotemeta($filename).'\s*::\s*([^\n]+)(?:\n|$)', $fileinfo_txt, $regs)) { return($regs[1]); } } // なければ、 if(is_dir($filepath)){ return('Directory'); } // ディレクトリ // ファイルの場合は$FileInfoのinfoから取得。 $extension = mb_ereg('[^\.]+\.(\w+)$', $filename, $regs) ? strtolower($regs[1]) : ''; if($extension && isset($FileInfo[$extension])){ return($FileInfo[$extension]['info']); } } elseif($fileinfo_txt) // 追加情報。ファイル名にマウスを当てたときツールチップとして表示。 { // $fileinfo_txtにデータがあればそれを取得。 if(mb_ereg('(?:^|\n)(?:'.quotemeta($dirpath).'/)?'.quotemeta($filename).'\s*::[^\n]*\n((?:[^\n]+\n)*?)(?:\n|[^\n]+::|$)', $fileinfo_txt, $regs)) { $info = strip_tags(trim($regs[1])); $info = mb_ereg_replace('"', '"', $info); $info = mb_ereg_replace('\r|\n', '', $info); return($info); } } return(''); } function download($src) { global $ResumeOption; $filename = filename($src); // ファイルタイプヘッダーの出力 if($filetype = contenttype($filename)) { if(mb_ereg('text/', $filetype)) { $text_contents = file_get_contents($src, NULL, NULL, 0, 65534); $encode = mb_detect_encoding($text_contents); // charsetを実際のファイルから得る。 if($encode == 'SJIS'){ $charsetorder = '; charset=Shift_JIS'; } elseif($encode == 'EUC-JP'){ $charsetorder = '; charset=EUC-JP'; } elseif($encode == 'UTF-8'){ $charsetorder = '; charset=UTF-8'; } elseif($encode == 'JIS'){ $charsetorder = '; charset=ISO-2022-JP'; } else{ $charsetorder = ''; } // わからんときは書かない。 if(isset($_REQUEST['view'])) // 生のテキストソースを表示するようにtext/plainを指定。 { header('Content-Type: text/plain'.$charsetorder); } else { header('Content-type: '.$filetype.$charsetorder); } } else { header('Content-type: '.$filetype); } } else // ファイル情報の一覧からファイルタイプを確定できない場合。 { $filetype = shell_exec('file -biL "'.$src.'"'); if(mb_ereg('[^/]+/[^;]+;', $filetype)) { header('Content-type: '.$filetype); } else { header('Content-type: application/octet-stream'); } } header('X-Content-Type-Options: nosniff'); // だめブラウザが勝手にファイルタイプを決めるのを防止。 // Windowsはファイル名をrawurlencodeしないと日本語が文字化けする。 if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match('%Windows %', $_SERVER['HTTP_USER_AGENT'])) { $urlfilename = rawurlencode($filename); } else { $urlfilename = $filename; } // 表示かダウンロードか。 if(isset($_REQUEST['inline']) || isset($_REQUEST['stream']) || isset($_REQUEST['view'])) // そのまま表示。 { header('content-disposition: inline; filename="'.$urlfilename.'"'); } else // ダウンロード強制。 { header('content-disposition: attachment; filename="'.$urlfilename.'"'); } // 検索ロボットにインデックス、キャッシュ等はさせない。写真などがさらされる。 // またhtmlファイルなどはrobotにインデックスされるとサンプルのURLやこのフォルダからのリンクが指定されてエラーになる。 header('X-Robots-Tag: noindex,nofollow,noarchive'); // キャッシュコントロール。確実にダウンロードさせるなら決してキャッシュさせてはいけない(キャッシュが表示されてしまう)が、 // ブラウザ、プロキシサーバー、キャッシュサーバー等によってどれか一つでOKとはいかないようで、みんな書いておこう。 header('Expires: 0'); header('Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0'); //// 以下、出力。 // 頭が"!"のテキストファイルの表示は特別。案内等に使う。タグは取り除いてタグエンティティーを戻しテキスト表示。 // ファイルサイズは変わるのでContent-Lengthは出力しない。なくてもだいじょうぶ。 if(isset($_REQUEST['view']) && mb_eregi('^!.*\.txt$', $filename)) { $fp = fopen($src, "r"); while($text = fgets($fp)) { $text = strip_tags($text); $text = mb_ereg_replace('<', '<', $text); $text = mb_ereg_replace('>', '>', $text); echo($text); } fclose($fp); return; } // ダウンロード。 set_time_limit(300); // 時間制限。大きな動画ファイルなどがあるときはそれなりに。0は制限しない。 $file_size = filesize($src); if(empty($ResumeOption)) // 中断再開や部分ダウンロードには対応しない場合。 { header('Content-Length: '.$file_size); header('Accept-Ranges: none'); // ダウンロード範囲の指定は受け付けない。 ob_flush(); $fp = fopen($src, 'rb'); while(connection_status() == 0 && !feof($fp)) { print(fread($fp, 4096)); // 4096はphp.iniのoutput_bufferingの値。ただしfread()の読込可能最大値は8192。これ以上は読めない。以下同様。 ob_flush(); flush(); } fclose($fp); } else // 中断再開、部分ダウンロード対応。 { if(empty($_SERVER['HTTP_RANGE'])) // RANGE指定はない。ファイルをすべて出力。 { header('Content-Length: '.$file_size); header('Accept-Ranges: bytes'); // ダウンロード範囲の指定をバイト単位で受け付ける。これにより中断再開、部分ダウンロードが可能。 ob_flush(); $fp = fopen($src, 'rb'); while(connection_status() == 0 && !feof($fp)) { print(fread($fp, 4096)); ob_flush(); flush(); } fclose($fp); } else // RANGE指定あり。 { list($size_unit, $range_orig) = explode('=', $_SERVER['HTTP_RANGE'], 2); if($size_unit != 'bytes') { header('HTTP/1.1 416 Requested Range Not Satisfiable'); return; } $range_requests = explode(',', $range_orig); if(!isset($range_requests[1])) // マルチレンジ要求でなければ!。複数range(multipart)対応は難しい。 { $range = $range_requests[0]; if($range){ list($seek_start, $seek_end) = explode('-', $range); } // 参考: http://www.studyinghttp.net/cgi-bin/rfc.cgi?2616#Sec14.35.1 if(isset($seek_start) && $seek_start != '' && isset($seek_end) && $seek_end != '') { $seek_start = max(intval($seek_start), 0); $seek_end = min(intval($seek_end), ($file_size - 1)); } elseif(isset($seek_start) && $seek_start != '') { $seek_start = max(intval($seek_start), 0); $seek_end = $file_size - 1; } elseif(isset($seek_end) && $seek_end != '') { $seek_start = max(($file_size-intval($seek_end)), 0); // 注意:$seek_start=0ではない。最後のseek_endバイトを送る!。 $seek_end = $file_size - 1; } else // すべてを送る。(不正な範囲リクエストはエラーにせず範囲リクエストを無視する。) { $seek_start = 0; $seek_end = $file_size - 1; } if($seek_end < $seek_start) // すべてを送る。(同上。) { $seek_start = 0; $seek_end = $file_size - 1; } if($seek_start > 0 || $seek_end < ($file_size - 1)) // 部分ダウンロードの場合。 { header('HTTP/1.1 206 Partial Content'); header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$file_size); } header('Content-Length: '.($seek_end - $seek_start + 1)); header('Accept-Ranges: bytes'); // ダウンロード範囲の指定をバイト単位で受け付ける。これにより中断再開、部分ダウンロードが可能。 // 内容を出力。 ob_flush(); $fp = fopen($src, "rb"); fseek($fp, $seek_start); while(connection_status() == 0 && $seek_start <= $seek_end && !feof($fp)) { $read_length = min(4096, $seek_end - $seek_start + 1); // 4096はphp.iniのoutput_bufferingの値。ただしfread()の読込可能最大値は8192。これ以上は読めない。 print(fread($fp, $read_length)); ob_flush(); flush(); $seek_start += $read_length; } fclose($fp); } else // multipart対応はできていない。すべて送る。 { header('Content-Length: '.$file_size); header('Accept-Ranges: none'); // ダウンロード範囲指定の受付けはひっこめる。 ob_flush(); $fp = fopen($src, 'rb'); while(connection_status() == 0 && !feof($fp)) { print(fread($fp, 4096)); ob_flush(); flush(); } fclose($fp); } } } } function error_404() { global $Encoding; header("HTTP/1.0 404 Not Found"); echo(' Object not found!

Object not found or Unreadable!

要求された URL は本サーバでは見つかりませんでした。 あるいは読み出すことができません。
もし手入力で URL を入力した場合は、綴りを確認して再度お試し下さい。

サーバーの障害と思われる場合は、ウェブ管理者までご連絡ください。

Error 404

'.$_SERVER['SERVER_NAME'].'
'.$_SERVER['SERVER_SOFTWARE'].'
'); } // 以上、各定義。ここから実質処理をスタート。 $src = ''; if(isset($_REQUEST['dir'])) { $src = mb_convert_encoding($_REQUEST['dir'], $Encoding, mb_detect_encoding($_REQUEST['dir'])); // 絶対パスや上位ディレクトリ、隠しディレクトリ(頭が".")、へんな文字コードがあるの、ディレクトリでないの、読めないのなどはだめ。 if(mb_ereg('^/|\.\.+/|^\.(?!/|$)|/\.|~$|[\x00-\x1F\x7F]', $src) || !is_dir($src) || !is_readable($src)) { error_404(); // 余計な情報を与える必要もないので表示しない(あるいはできない)ものはみな404にしておく。 exit; } } elseif(isset($_REQUEST['file'])) { $src = mb_convert_encoding($_REQUEST['file'], $Encoding, mb_detect_encoding($_REQUEST['file'])); // 絶対パスや上位ディレクトリ、隠しファイル(頭が".")、バックアップファイル、へんな文字コードがあるの、ファイルでないの、読めないのなどはだめ。 if(mb_ereg('^/|\.\.+/|^\.(?!/)|/\.|~$|[\x00-\x1F\x7F]', $src) || !is_file($src) || !is_readable($src)) { error_404(); // 余計な情報を与える必要もないので表示しない(あるいはできない)ものはみな404にしておく。 exit; } } if(!$src || is_dir($src)) // トップまたはディレクトリの指定。 { showindex($src); // インデックスリストを表示 } elseif(is_file($src)) { download($src); // ファイルをダウンロード } else { error_404(); exit; } exit; ?>