웹마스터 팁
게시판글 엑셀 파일 보내기 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
제목 | 글쓴이 | 날짜 |
---|---|---|
(회원가입) 닉네임 필요없이 이름만 입력 받으려면 [16] | Simulz | 2007.08.22 |
rewrite mod 설정, 해지 [1] | 아름드리479 | 2007.08.22 |
설치환경을 갖추어도 설치시 문제 [1] | 하얀후니 | 2007.08.22 |
로고 위치 변경하기 [4] | 김영훈715 | 2007.08.21 |
홈페이지 주소 고정시키기 [12] | :에반: | 2007.08.21 |
zbxe 일주일 사용기 및 팁 [1] | 팔공산 | 2007.08.21 |
layout skin 제작시 info.xml도 잘 보세요 [1] | 바람처럼.. | 2007.08.21 |
페이지 수정시 메뉴들 가지런히 놓이게 하기 [3] | 팔공산 | 2007.08.21 |
(수정) ZBXE 설치/로그인 등이 안될 때 시도해보세요. (MySQL DB) | 핑크플로이드 | 2007.08.20 |
OpenID 적용 [6] | 맑은하늘75 | 2007.08.20 |
게시판에 나타나는 이름을 실명으로 나타내자! [5] | 박영주964 | 2007.08.19 |
각 메뉴 옆에 게시물 갯수 표시하기 [6] | coolsushi | 2007.08.19 |
본문 하단에 (애드센스)광고 넣기 [2] | roresy | 2007.08.19 |
한글 경로가 404 에러로 뜨는 경우 처리방법 [2] | 베니 | 2007.08.18 |
404 페이지 못찾음으로 나오는 문제 수정 [9] | 화니군 | 2007.08.18 |
리눅스에서 제로보드 xe를 위한 환경 구축하기 [6] | 써니a | 2007.08.18 |
사이트접속시 제로보드XE폴더로 이동되게 하는 쉬운방법 [8] | 부찬™ | 2007.08.17 |
위지웍 에디터 웹폰트 사용하기 [6] | 최지연 | 2007.08.17 |
서브 메뉴 배경색 바꾸기 [4] | Chang-Jo(창조) | 2007.08.17 |
4차 서브메뉴 사용하기!! [4] [1] | 럭키587 | 2007.08.17 |