<?
include_once ($_SERVER[DOCUMENT_ROOT] . "/common/conf/config.inc.php");
include_once ($_SERVER[DOCUMENT_ROOT] . "/module/online/online.lib.php");

//DB연결
$dblink = SetConn($_conf_db["main_db"]);

$arrFile = getOnlineFileInfo(mysql_real_escape_string($_GET[boardid]), mysql_real_escape_string($_GET[b_idx]), mysql_real_escape_string($_GET[idx]));

if($arrFile["total"] > 0){
	$src_file = $_SERVER[DOCUMENT_ROOT] . "/uploaded/online/" . $arrFile["list"][0][re_name];

	if(!$_REQUEST[mode]){	

		//다운로드 수 업데이트
		$sql  = "UPDATE " .$GLOBALS["_conf_tbl"]["board_files"]." SET ";
		$sql .= " download = download + 1 ";
		$sql .= "WHERE idx = '".$arrFile["list"][0][idx]."' ";
		
		mysql_query($sql, $GLOBALS[dblink]);

		if($arrFile["list"][0][ext]=="swf"){
			$size = GetImageSize($src_file);
			$width = $size[0]+10;
			$height = $size[1]+28;
			echo"
			<script language=javascript> 
			  resizeTo($width,$height)
			  moveTo(0,0)
			</script>
			<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
			<div align=center>	
			<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' $size[3]>
			  <param name=movie value='$src_file'>
			  <param name=quality value=high>
			  <param name=BGCOLOR value=''>
			  <param name='SCALE' value='exactfit'>
			  <embed src='$src_file' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' scale='exactfit' bgcolor='' $size[3]>
			  </embed> 
			</object>
			</div>
			";
			exit;
		}elseif($arrFile["list"][0][ext]=="gif" || $arrFile["list"][0][ext]=="jpg" || $arrFile["list"][0][ext]=="png" || $arrFile["list"][0][ext]=="bmp")
		{
			$size = GetImageSize($src_file);
			$width = $size[0]+30;
			$height = $size[1]+55;
			echo"
			<script language=javascript> 
			  resizeTo($width,$height)
			  moveTo(0,0)
			</script>
			";		
			
			$go_url = $_SERVER[PHP_SELF] . "?mode=img_view&boardid=" . $boardid . "&no=" . $no;
			jsGo($_SERVER[PHP_SELF]."?mode=img_view&boardid=".$_GET[boardid]."&b_idx=".$_GET[b_idx]."&idx=".$_GET[idx],"","");
			exit;
		}else{//일반파일일때
			fileDownload($src_file, iconv("UTF-8","EUC-KR",$arrFile["list"][0][ori_name]));	

		}
	}elseif($_REQUEST[mode]=='img_view'){
		/*
		if (is_file($src_file)){
			$fp = fopen($src_file, "r"); 
			if (!fpassthru($fp)){ 
			fclose($fp);
			} 
		}
		*/
		header("Content-Type: " .$arrFile["list"][0][type]);
		header("Content-Length: " . filesize($src_file));

		if (is_file($src_file)){
			$fp = fopen($src_file, "r"); 
			if (!fpassthru($fp)){ 
			fclose($fp);
			} 
		}

	}
}else{
	jsMsg('해당 파일이 없습니다.');
	selfClose();
}
//DB해제
SetDisConn($dblink);
?>