mySQL 자료 엑셀,워드,파워포인트로 다운받기 > 기술자료

본문 바로가기

사이트 내 전체검색

mySQL 자료 엑셀,워드,파워포인트로 다운받기 > 기술자료

PHP mySQL 자료 엑셀,워드,파워포인트로 다운받기

페이지 정보


본문

<?php
/*
include_once("./_common.php");
if (!$is_admin =="super")
  alert_close("최고 관리자 영역 입니다.");
include "dbconfig.php";
*/
$mysql_host     = "localhost";
$mysql_user     = "아이디";
$mysql_password = "비밀번호";
$mysql_db       = "데이타베이스";
$dbconn = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_db);

// 그누보드5 사용시
//include_once "../common.php"; // 그누브도5 common.php 경로
//$dbconn = mysqli_connect(G5_MYSQL_HOST,G5_MYSQL_USER,G5_MYSQL_PASSWORD,G5_MYSQL_DB) ;

if (!$dbconn) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

//@mysqli_query("set names utf8");   // 한글문제 생기면 주석 해제
$file_type   = "excel"; // 문서다운로드 형태 // excel , powerpoint , word , notepad
$file_name   = "파일명"; // ex: 문서.xls 일때는  문서 를 입력
$down_date   = date("Y-m-d_His"); // 다운로드 날짜(년-월-일_시분초)
$DB_table    = "테이블이름";
$orderidx    = "num"; // DB 테이블 고유번호
$sql_orderby = " order by {$orderidx} desc"; // 정렬조건

$sql = "select * from {$DB_table}{$sql_orderby}";
$qry = mysqli_query($sql);
$tot = mysqli_num_rows($qry); // 전체개수
//echo "tot = ".$tot."<br>";
//echo "sql = ".$sql."<br>";

header( "Content-type: application/vnd.ms-excel; charset=utf-8" );
header( "Content-Disposition: attachment; filename=".$filename.".xls" );

if ($file_type =="excel") {
    $title = "엑셀 문서 다운로드";
    header( "Content-type: application/vnd.ms-excel; charset=utf-8" );
    header( "Content-Disposition: attachment; filename={$file_name}_{$down_date}.xls" );
    //header( "Content-Description: PHP4 Generated Data" );
} else if ($file_type =="powerpoint") {
    $title = "파워포인트 문서 다운로드";
    header( "Content-type: application/vnd.ms-powerpoint; charset=utf-8" );
    header( "Content-Disposition: attachment; filename={$file_name}_{$down_date}.ppt" );
    // header( "Content-Description: PHP4 Generated Data" );
} else if ($file_type =="word") {
    $title = "워드 문서 다운로드";
    header( "Content-type: application/vnd.ms-word; charset=utf-8" );
    header( "Content-Disposition: attachment; filename={$file_name}_{$down_date}.doc" );
    //header( "Content-Description: PHP4 Generated Data" );
} else if ($file_type =="notepad") {
    $title = "메모 문서 다운로드";
    header( "Content-type: application/vnd.ms-notepad; charset=utf-8" );
    header( "Content-Disposition: attachment; filename={$file_name}_{$down_date}.txt" );
} else {
    header( "Content-type: application/vnd.ms-excel; charset=utf-8" );
    header( "Content-Disposition: attachment; filename={$file_name}_{$down_date}.xls" );
}
?>
<head>
<head>
<title><?php echo $title; ?></title>
<style type="text/css">
.txt {mso-number-format:'\@'}
</style>
</head>

<body>
<table>
    <tr>
        <th>번호</th>
        <th>이름</th>
        <th>이메일</th>
    </tr>
    <?php
    $id_num = 0;
    while($row = mysqli_fetch_array($qry)) {
        $idx_num = $tot - $id_num;
        $index_num = $row['num']; // 고유번호
    ?>
    <tr>
        <td><?php echo $idx_num; ?></td>
        <td class="txt"><?php echo $row['name']; ?></td>
        <td class="txt"><?php echo $row['email']; ?></td>
    </tr>
    <?php
        $idx_num--;
    }
    ?>
</table>
</body>
</html>


참고사이트
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=2198
http://flashcafe.org/3950
 

댓글목록

등록된 댓글이 없습니다.


Total 2,650건 88 페이지
  • RSS
기술자료 목록
910
Editor   19744  2010-06-28 18:03 ~ 2017-11-08 17:56  
909
일반   41956  2010-06-26 10:44  
908
WindowsServer   20511  2010-06-21 20:29 ~ 2016-01-26 00:00  
907
Linux   35752  2010-06-21 20:29 ~ 2017-04-11 00:00  
906
ClassicASP   17074  2010-06-20 03:23 ~ 2013-06-14 00:00  
905
Linux   12645  2010-06-19 09:55  
904
일반   17987  2010-06-16 15:50  
903
일반   10645  2010-06-16 10:33  
902
JavaScript   21458  2010-06-12 11:55  
901
메이크샵   11121  2010-06-10 18:49  
900
ClassicASP   40900  2010-06-09 23:19 ~ 2012-12-04 00:00  
899
그누보드   13911  2010-05-18 19:54  
898
MySQL   18314  2010-05-14 09:20  
897
Adobe   48421  2010-05-02 13:05  
896
MSSQL   22528  2010-04-26 22:35  
895
일반   14410  2010-04-15 22:38  
894
그누보드   13053  2010-04-15 19:03  
893
일반   15637  2010-04-14 21:54 ~ 2010-04-14 00:00  
892
PHP   28456  2010-04-13 23:06  
891
일반   13827  2010-04-09 12:32 ~ 2010-04-15 00:00  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2026 해피정닷컴. All Rights Reserved.