paramCHK( $_GET["offset"], $_GET["count"], $_GET["name"] ) ){ $fileDL->run(); }else{ $fileDL->retMess(2); } exit(); /**/ class up_download { var $offsetx, $countx, $namex, $contLen; function paramCHK( $offset, $count, $name ) { $this->offsetx = intval( $offset ); $this->countx = intval( $count ); $this->contLen = $this->countx - $this->offsetx; $this->namex = htmlspecialchars( $name, ENT_QUOTES ); if( !ereg( "^[0-9a-zA-Z_\-]{1,15}\.kjx$", $this->namex ) || !is_file( $this->namex ) ){ return FALSE; } else{ return TRUE; } } function run() { if ( $this->offsetx >= 0 && $this->countx > 0 ){ $fp = fopen ( $this->namex, "r" ); fseek( $fp, $this->offsetx, SEEK_SET ); $buf = fread( $fp, $this->countx ); fclose ( $fp ); header("Content-type: application/x-up-download"); echo $buf; } elseif( $this->offsetx == 0 && $this->countx == 0 ){ header("Content-type: application/x-up-download"); header("Content-length: 0"); echo "\n"; } elseif( $this->offsetx == -1 && $this->countx == 0 ){ $this->retMess(1); } elseif( $this->offsetx == -1 && $this->countx == -1 ){ $this->retMess(0); } } function retMess( $code ) { header("Content-type: text/x-hdml;charset=Shift_JIS"); echo "\n"; echo "\n"; echo "\n"; switch ( $code ){ case 0: echo "ダウンロード失敗しました。\n"; break; case 1: echo "ダウンロード成功しました。\n"; break; case 2: echo "ファイル[ {$this->namex} ]は存在しません。\n"; break; } echo "\n"; echo "\n"; } } ?>