Home » News » 그누보드 엑셀 다운로드 php

그누보드 엑셀 다운로드 php

<?php

include_once('./_common.php');

$bo_table = $_REQUEST['bo_table'];
$write_table = 'g5_data_write_' . $bo_table;
$export_file_name= $bo_table .'-'.date('Ymdhis').'.csv';

header("Content-Description: File Transfer");
header('Content-Type:text/csv;charset=UTF-8;');
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=" . $export_file_name);
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

$handle = fopen('php://output', 'w');

ob_clean(); // clean slate

$sql = "
    select
    	wr_id as '일련번호' 
        , wr_1 'ftc.go.kr 고유번호'
        , ca_name '업종', wr_subject '상호'
        , wr_link2 '영업표지'
        , wr_name '대표'
        , wr_facebook_user '사업자 등록번호'
        , wr_2 '주소'
        , wr_3 '대표번호'
        , wr_4 '매출액(n-1)'
        , wr_5 '매출액(n-2)'
        , wr_6 '매출액(n-3)'
        , wr_7 '가맹점수(n-1)'
        , wr_8 '가맹점수(n-2)'
        , wr_9 '가맹점수(n-3)'
        , wr_datetime '최근등록일'
        , wr_twitter_user '최초등록일'
        , wr_last '최종업데이트'
        , wr_link1 
    from {$write_table}
";

$result = sql_query($sql);

echo "\xEF\xBB\xBF";

$header_array = array('일련번호', 'ftc.go.kr 고유번호', '업종', '상호', '영업표지', '대표', '사업자등록번호', '주소', '대표번호', '매출액(n-1)', '매출액(n-2)', '매출액(n-3)', '가맹점(n-1)', '가맹점(n-2)', '가맹점(n-3)', '최근등록일' , '최초등록일', '최종업데이트', '링크');

fputcsv($handle, $header_array);

while ($row = sql_fetch_array($result)) {
    fputcsv($handle, $row);   // direct to buffered output
}

ob_flush(); // dump buffer

fclose($handle);

die();

?>

답글 남기기