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 196건 8 페이지
  • RSS
기술자료 목록
56
PHP   16422  2009-04-17 19:59 ~ 2010-03-21 00:00  
55
PHP   27370  2009-01-31 10:50  
54
PHP   19985  2009-01-16 20:00  
53
PHP   18098  2009-01-05 20:07  
52
PHP   17612  2008-12-31 05:34 ~ 2022-11-30 12:11  
51
PHP   16386  2008-12-17 21:15  
50
PHP   16079  2008-12-17 21:02 ~ 2018-10-09 09:21  
49
PHP   25570  2008-10-29 10:33 ~ 2013-04-06 00:00  
48
PHP   17582  2008-08-27 17:46  
47
PHP   13311  2008-08-12 12:13  
46
PHP   14827  2008-06-21 18:14  
45
PHP   16465  2008-04-26 16:50 ~ 2021-07-06 21:53  
44
PHP   23112  2008-04-26 15:59 ~ 2013-01-14 00:00  
43
PHP   15950  2008-04-26 15:05 ~ 2009-09-16 00:00  
42
PHP   15941  2008-04-21 23:09  
41
PHP   17913  2008-04-21 12:02 ~ 2021-08-17 23:30  
40
PHP   13706  2008-01-22 17:03  
39
PHP   24594  2008-01-10 01:01 ~ 2008-02-10 00:00  
38
PHP   15631  2008-01-07 22:40  
37
PHP   17380  2008-01-04 00:15 ~ 2022-11-18 10:28  

검색

해피정닷컴 정보

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

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