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
/*
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
댓글목록
등록된 댓글이 없습니다.