<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가 

// SWFupload - No Mobile, Yes Member Ok!
if (!G5_IS_MOBILE && $amina['uploader'] == "1" && $member['mb_id']) { 
    $sql = "select * from {$g5['amina_file']} where bo_table = '$bo_table' and mb_id = '{$member['mb_id']}' and bf_ip = '{$_SERVER['REMOTE_ADDR']}' order by bf_no";
    $qry = sql_query($sql, false);
    for ($i=0; $row=sql_fetch_array($qry); $i++) {
        $source = G5_DATA_PATH.'/upload/'.$row['bf_file'];
        $dest = G5_DATA_PATH.'/file/'.$bo_table.'/'.$row['bf_file'];
        @copy($source, $dest);
        @unlink($source);
        sql_query("insert into {$g5['board_file_table']}
                   set bo_table = '$bo_table'
                     , wr_id = '$wr_id'
                     , bf_no = '{$row['bf_no']}'
                     , bf_source = '".addslashes($row['bf_source'])."'
                     , bf_file = '".addslashes($row['bf_file'])."'
                     , bf_download = 0
					 , bf_filesize = '{$row['bf_filesize']}'
                     , bf_width = '{$row['bf_width']}'
                     , bf_height = '{$row['bf_height']}'
                     , bf_type = '{$row['bf_type']}'
                     , bf_datetime = '{$row['bf_datetime']}'");
    }
    sql_query("delete from {$g5['amina_file']} where bo_table = '$bo_table' and mb_id = '{$member['mb_id']}' and bf_ip = '{$_SERVER['REMOTE_ADDR']}'", false);

	//쓰레기파일 삭제
	$uptimes = date('Y-m-d H:i:s', time()-60*60*3 );
    $sql3= "select * from {$g5['amina_file']} where bf_datetime < '$uptimes' ";

    $qry3 = sql_query($sql3, false);
    while($row3=sql_fetch_array($qry3)){
		sql_query("delete from {$g5['amina_file']} where id = '{$row3['id']}'");
		$source2 = G5_DATA_PATH.'/upload/'.$row3['bf_file'];
		@unlink($source2);
	}

	//G5 wr_file 업데이트
	if(AMINA && $i > 0) {
		sql_query(" update {$write_table} set wr_file = '{$i}' where wr_id = '{$wr_id}' ");
	}
}
?>