웹마스터 팁
게시판글 엑셀 파일 보내기 php7용
2018.06.05 19:01
<?php
//url 로 직접 불러오는것을 방지
if(!strstr($_SERVER['HTTP_REFERER'],$_SERVER['SERVER_NAME'])&& !strstr($_SERVER['HTTP_REFERER'],'out_excel.php')) exit;
$servername = "localhost";
$username = "user ID";
$password = "DB_password";
$table = "xe_documents";
$database = "DB name";
$module_srl = "module srl"; // 숫자 입력
$con = new mysqli($servername,$username,$password,$database);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$getcolumns = array("title"); //출력원하는 칼럼을 배열로 입력
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=doc_".date('Ymd').".xls");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=Content-Type content=text/html; charset="utf-8">
</head>
<body>
<table border=1>
<tr align=center>
<?php
//제목 불러오기
$sql = "SHOW COLUMNS FROM $database.$table";
$dbcolumns = mysqli_query($con,$sql); //xe_documents에서 칼럼값 불러오기
// fetch associative array
while ($rowname = mysqli_fetch_row($dbcolumns)) {
if( in_array($rowname[0], $getcolumns) ) echo "<th>".$rowname[0]."</th>";
}
//확장변수의 타이틀은 값이므로
$result = mysqli_query($con, "select var_name from xe_document_extra_keys where module_srl = $module_srl");
while( $data = mysqli_fetch_array($result) ){
echo "<th>".htmlspecialchars($data[var_name])."</th>";
}
echo"</tr>";
//데이터 불러오기
$result = mysqli_query($con, "select * from $table where module_srl=$module_srl");
while( $data = mysqli_fetch_assoc($result) ){
echo"<tr>";
foreach( $data as $key => $val ){
if( in_array($key, $getcolumns) ){
if ($key == 'regdate'){
echo "<td style='mso-number-format:\"0_ \";' >".htmlspecialchars($val)."</td>";
}elseif ($key == 'content'){ //내용 출력할경우 태그가 그대로 출력됨
//echo "<td>".$val."</td>"; //셀이 두칸이상으로 늘어남
echo "<td >".htmlspecialchars(strip_tags(str_replace(" ","",$val)))."</td>";
}else {
echo "<td>".htmlspecialchars($val)."</td>";
}
}
if ($key == 'document_srl'){ //확장변수 불러올때 사용
$d_srl=$val;
}
}
//확장변수 출력 ////////////////////////////////////////////
//eid리스트를 불러온다
$query=mysqli_query($con, "select eid from xe_document_extra_keys where module_srl = $module_srl");
while($extra_title=mysqli_fetch_array($query)){
echo"<td>";
$egetFields = array("value","eid"); //확장변수 값을 불러와 eid값이 같은곳에 출력
$extra_result = mysqli_query($con, "select * from xe_document_extra_vars where document_srl = $d_srl");
while( $edata = mysqli_fetch_assoc($extra_result) ){
$extra_str="";
foreach( $edata as $key => $val ){
if( in_array($key, $egetFields) ){
$extra_str = $val.",".$extra_str;
}
}
$extra_arr=explode(",",$extra_str);
if ($extra_title[eid]==$extra_arr[0]){
//전화번호값은 "|@|" 를 "-" 로 변경
if($extra_title[eid]=="mb_phone_Number"){
echo str_replace("|@|","-",htmlspecialchars($extra_arr[1]));
//기타 배열값들은 ',' 로 변경
}elseif($extra_title[eid]=="mb_incomplete"||$extra_title[eid]=="mb_cs"){
echo str_replace("|@|",",",htmlspecialchars($extra_arr[1]));
}else{
echo htmlspecialchars($extra_arr[1]);
}
}
}
echo"</td>"; //eid값이 없으면 빈칸입력
}
/////////////////////////////////////////////////////////////////////
echo"</tr>";
}
mysqli_close($con);
?>
</table>
</body>
</html>
------------------------------------------------------------------------------------------------------------------
글을 조금 수정해서 php7에서 사용할 수 있도록 했습니다.
만약, 오류가 나더라도 답변할 실력이 안됩니다.
centos 7, php7.2 에서 테스트 했습니다.
댓글 0
제목 | 글쓴이 | 날짜 |
---|---|---|
플래시메뉴 사입방법 [4] | urhow1 | 2007.08.29 |
분류가 있는 게시판에서 전체분류모드로 게시물 클릭시 딜레이 현상 [2] | Sx3 | 2007.08.30 |
페이지수정 안되시는 분들께 드리는 팁 [2] | 다케루 | 2007.08.30 |
구글광고넣기....(재밌는경험담 본문에 광고 넣으시려는분 꼭 읽어 보세요...) [2] | kangho | 2007.08.30 |
회원 단축 메뉴 보여주기 | Simulz | 2007.08.30 |
(최근글목록) 분류명 표시하기 & 이미지 [7] | Simulz | 2007.08.31 |
서버이전하고 마이그레이션하고 경험담 [3] | 팔공산 | 2007.08.31 |
(최근글목록) 게시판 이름 출력하기 #2 [12] | Simulz | 2007.08.31 |
관리자 아이디 사용제한 체크하는 어이없는 실수 & 해결 [5] | refree | 2007.09.01 |
(0.1.2) 이모티콘 삽입 후 그림 안보일 때 [5] | Simulz | 2007.09.02 |
랜덤 배경 이미지 [7] | Simulz | 2007.09.04 |
(설문조사) 회원만 설문 조사 하도록 [8] | Simulz | 2007.09.04 |
회원에게는 구글 애드센스 보이지 않게 하기 [2] | 스컬리지금어디야 | 2007.09.05 |
글이 중간에 짤릴 경우.. | 송암 | 2007.09.06 |
확장변수 이용해서 2차 3차 분류 항목 만들기 [3] | VagaBond | 2007.09.08 |
(게시판) 목록에 확장 변수를 출력하기 [18] | Simulz | 2007.09.08 |
메인 페이지 링크 www. 주소 표시, 로그인 링크 문제.... [5] | 마덴나 | 2007.09.08 |
(파일 첨부) 파일명 안보일 때 ... 없애기 [9] | Simulz | 2007.09.10 |
랭킹에 순위 넣기! ㅋ~ (꼼수;) | 다케루 | 2007.09.11 |
파일 업로드시에 403에러 발생시 해결방법. [12] | WhiteAT | 2007.09.12 |