엑셀 업로드 질문
본문
Fatal error: Uncaught Error: Undefined constant "ex_type" in /finenuts05/www/skin/board/basic/excel_free_up2.php:8 Stack trace: #0 {main} thrown in /finenuts05/www/skin/board/basic/excel_free_up2.php on line 8
이런 에러가 나오면서 안넘어갑니다...
다운로드는 또 잘되는 상황입니다..
아래에 코드 첨부했습니다.
list.skin.php
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 8;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
?>
<!-- 게시판 목록 시작 { -->
<div id="bo_list" style="width:<?php echo $width; ?>">
<!-- 게시판 카테고리 시작 { -->
<?php if ($is_category) { ?>
<nav id="bo_cate">
<h2><?php echo $board['bo_subject'] ?> 카테고리</h2>
<ul id="bo_cate_ul">
<?php echo $category_option ?>
</ul>
</nav>
<?php } ?>
<!-- } 게시판 카테고리 끝 -->
<div class="tbl_head01 tbl_wrap">
<form id="fsearch" name="fsearch" method="get">
<fieldset id="bo_sch">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sop" value="or">
<input type="hidden" name="chk_wr_id" value="">
<label for="sfl" class="sound_only">검색대상</label>
<select name="sfl" id="sfl" class="sel_box_btn">
<?php echo get_board_sfl_select_options($sfl); ?>
</select>
<label for="stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx" value="<?php echo stripslashes($stx) ?>" id="stx" class="sch_input" size="25" maxlength="20" placeholder="검색어를 입력해주세요">
<button type="button" onclick="fsearch.submit()" class="sch_btn"><i class="fa fa-search" aria-hidden="true"></i><span class="sound_only">검색</span></button>
</fieldset>
</form>
</div>
<form name="fboardlist" id="fboardlist" action="<?php echo G5_BBS_URL; ?>/board_list_update.php" onsubmit="return fboardlist_submit(this);" method="post">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<input type="hidden" name="sfl" value="<?php echo $sfl ?>">
<input type="hidden" name="stx" value="<?php echo $stx ?>">
<input type="hidden" name="spt" value="<?php echo $spt ?>">
<input type="hidden" name="sca" value="<?php echo $sca ?>">
<input type="hidden" name="sst" value="<?php echo $sst ?>">
<input type="hidden" name="sod" value="<?php echo $sod ?>">
<input type="hidden" name="page" value="<?php echo $page ?>">
<input type="hidden" name="sw" value="">
<!-- 게시판 페이지 정보 및 버튼 시작 { -->
<div id="bo_btn_top">
<div id="bo_list_total">
<span>전체 <?php echo number_format($total_count) ?>건</span>
</div>
<ul class="btn_bo_user">
<?php if ($admin_href) { ?><li><a href="<?php echo $admin_href ?>" class="btn_admin btn" title="관리자"><i class="fa fa-cog fa-spin fa-fw"></i><span class="sound_only">관리자</span></a></li><?php } ?>
<?php if ($rss_href) { ?><li><a href="<?php echo $rss_href ?>" class="btn_b01 btn" title="RSS"><i class="fa fa-rss" aria-hidden="true"></i><span class="sound_only">RSS</span></a></li><?php } ?>
<?php if ($is_admin == 'super' || $is_auth) { ?>
<li>
<button type="button" class="btn_more_opt is_list_btn btn_b01 btn" title="게시판 리스트 옵션"><i class="fa fa-ellipsis-v" aria-hidden="true"></i><span class="sound_only">게시판 리스트 옵션</span></button>
<?php if ($is_checkbox) { ?>
<ul class="more_opt is_list_btn">
<li><button type="submit" name="btn_submit" value="선택삭제" onclick="document.pressed=this.value"><i class="fa fa-trash-o" aria-hidden="true"></i> 선택삭제</button></li>
<li><button type="submit" name="btn_submit" value="선택복사" onclick="document.pressed=this.value"><i class="fa fa-files-o" aria-hidden="true"></i> 선택복사</button></li>
<li><button type="submit" name="btn_submit" value="선택이동" onclick="document.pressed=this.value"><i class="fa fa-arrows" aria-hidden="true"></i> 선택이동</button></li>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<!-- } 게시판 페이지 정보 및 버튼 끝 -->
<?php if ($is_admin) { ?>
<a href='<?php echo $board_skin_url; ?>/excel_free.php?bo_table=<?php echo $bo_table; ?>' class="btn_admin btn2 ex_btn" target='_blank'><i class="fa fa-user-circle" aria-hidden="true"></i> Excel (전체받기)</a>
<a class="ex_btn" href="<?php echo $board_skin_url?>/excel_free_up1.php?bo_table=<?php echo $bo_table?>">엑셀업로드</a>
<?php } ?>
<div class="tbl_head01 tbl_wrap">
<table>
<colgroup>
<?php
if ($is_admin) {
?>
<col width="10%">
<col width="10%">
<col width="10%">
<col width="40%">
<col width="15%">
<col width="20%">
<?php
}else{
?>
<col width="10%">
<col width="10%">
<col width="40%">
<col width="15%">
<col width="20%">
<?php
}
?>
</colgroup>
<caption><?php echo $board['bo_subject'] ?> 목록</caption>
<thead>
<tr>
<?php if ($is_checkbox) { ?>
<th scope="col" class="all_chk chk_box">
<input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);" class="selec_chk">
<label for="chkall">
<span></span>
<b class="sound_only">현재 페이지 게시물 전체선택</b>
</label>
</th>
<?php } ?>
<th scope="col">분야</th>
<th scope="col">경력</th>
<th scope="col">대표레퍼런스</th>
<th scope="col">근무형태</th>
<th scope="col">파견가능지역</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0; $i<count($list); $i++) {
if ($i%2==0) $lt_class = "even";
else $lt_class = "";
?>
<tr class="<?php if ($list[$i]['is_notice']) echo "bo_notice"; ?> <?php echo $lt_class ?>" onclick="location.href='<?php echo $list[$i]['href'] ?>'">
<?php if ($is_checkbox) { ?>
<td class="td_chk chk_box" onclick="event.cancelBubble=true">
<input type="checkbox" name="chk_wr_id[]" value="<?php echo $list[$i]['wr_id'] ?>" id="chk_wr_id_<?php echo $i ?>" class="selec_chk">
<label for="chk_wr_id_<?php echo $i ?>">
<span></span>
<b class="sound_only"><?php echo $list[$i]['subject'] ?></b>
</label>
</td>
<?php } ?>
<?php
if ($list[$i]['is_notice']) // 공지사항
echo '<strong class="notice_icon">공지</strong>';
else if ($wr_id == $list[$i]['wr_id'])
echo "<span class=\"bo_current\">열람중</span>";
?>
</td>
<td id="view_page" class="td_wr3">
<?php
if ($is_category && $list[$i]['ca_name']) {
?>
<a href="<?php echo $list[$i]['ca_name_href'] ?>" class="bo_cate_link"><?php echo $list[$i]['ca_name'] ?></a>
<?php } ?>
</td>
<td class="td_wr1"><?php echo $list[$i]['wr_1'] ?></td> <!-- ajob 여분필드 wr_1에 작성 한 값 불러오기 -->
<td class="td_wr15"><?php echo $list[$i]['wr_15'] ?></td> <!-- ajob 여분필드 wr_1에 작성 한 값 불러오기 -->
<td class="td_wr4"><?php echo $list[$i]['wr_4'] ?></td> <!-- ajob 여분필드 wr_4에 작성 한 값 불러오기 -->
<td class="td_wr5"><?php echo $list[$i]['wr_5'] ?></td> <!-- ajob 여분필드 wr_5에 작성 한 값 불러오기 -->
</tr>
<?php } ?>
<?php if (count($list) == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">게시물이 없습니다.</td></tr>'; } ?>
</tbody>
</table>
</div>
<!-- 페이지 -->
<?php echo $write_pages; ?>
<!-- 페이지 -->
<?php if ($list_href || $is_checkbox || $write_href) { ?>
<div class="bo_fx">
<?php if ($list_href || $write_href) { ?>
<ul class="btn_bo_user">
<?php if ($admin_href) { ?><li><a href="<?php echo $admin_href ?>" class="btn_admin btn" title="관리자"><i class="fa fa-cog fa-spin fa-fw"></i><span class="sound_only">관리자</span></a></li><?php } ?>
<?php if ($rss_href) { ?><li><a href="<?php echo $rss_href ?>" class="btn_b01 btn" title="RSS"><i class="fa fa-rss" aria-hidden="true"></i><span class="sound_only">RSS</span></a></li><?php } ?>
<?php if ($write_href) { ?><li><a href="<?php echo $write_href ?>" class="btn_b01 btn write_btn dis_none" title="글쓰기">글쓰기</a></li><?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
<?php if ($is_checkbox) { ?>
<ul class="btn_bo_adm">
<li><input type="submit" name="btn_submit" value="선택삭제" onclick="document.pressed=this.value"></li>
<li><button type="button" onclick="javascript:click_del('1','90');">90일 이전 자료 삭제</li>
<li><button type="button" onclick="javascript:click_del('2','0');">자료 초기화</li>
<li><button type="button" onclick="javascript:click_del('3','0');">금일자료 삭제</li>
</ul>
<?php } ?>
</form>
</div>
<?php if($is_checkbox) { ?>
<noscript>
<p>자바스크립트를 사용하지 않는 경우<br>별도의 확인 절차 없이 바로 선택삭제 처리하므로 주의하시기 바랍니다.</p>
</noscript>
<?php } ?>
<?php if ($is_checkbox) { ?>
<script>
function all_checked(sw) {
var f = document.fboardlist;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]")
f.elements[i].checked = sw;
}
}
function fboardlist_submit(f) {
var chk_count = 0;
for (var i=0; i<f.length; i++) {
if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
chk_count++;
}
if (!chk_count) {
alert(document.pressed + "할 게시물을 하나 이상 선택하세요.");
return false;
}
if(document.pressed == "선택복사") {
select_copy("copy");
return;
}
if(document.pressed == "선택이동") {
select_copy("move");
return;
}
if(document.pressed == "선택삭제") {
if (!confirm("선택한 게시물을 정말 삭제하시겠습니까?\n\n한번 삭제한 자료는 복구할 수 없습니다\n\n답변글이 있는 게시글을 선택하신 경우\n답변글도 선택하셔야 게시글이 삭제됩니다."))
return false;
f.removeAttribute("target");
f.action = g5_bbs_url+"/board_list_update.php";
}
return true;
}
// 선택한 게시물 복사 및 이동
function select_copy(sw) {
var f = document.fboardlist;
if (sw == "copy")
str = "복사";
else
str = "이동";
var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");
f.sw.value = sw;
f.target = "move";
f.action = g5_bbs_url+"/move.php";
f.submit();
}
// 게시판 리스트 관리자 옵션
jQuery(function($){
$(".btn_more_opt.is_list_btn").on("click", function(e) {
e.stopPropagation();
$(".more_opt.is_list_btn").toggle();
});
$(document).on("click", function (e) {
if(!$(e.target).closest('.is_list_btn').length) {
$(".more_opt.is_list_btn").hide();
}
});
});
</script>
<?php } ?>
excel_free_up1.php
<?php
include_once("_common.php");
$g5['title'] = "엑셀 업로드";
include_once(G5_PATH.'/_head.php');
?>
<style>
.new_excel{border-radius:20px;background:#fff;box-shadow:rgba(149, 157, 165, 0.1) 0px 8px 24px; padding:20px 20px 20px 20px; margin-top:20px;}
.new_excel h1{margin:10px 0;}
.excel_info {margin-bottom:10px; line-height:18px;}
.btn_confirm {margin-top:15px;}
.excel_desc{margin-top: 50px;}
.excel_desc .excel_tit{font-size: 1.333em;font-weight:700;}
.excel_desc .excel_con{margin-bottom:50px;margin-top: 20px;}
.excel_desc .excel_con p{padding-bottom: 10px;line-height:26px;}
.excel_desc .excel_con img{width: 100%;border:1px solid #ccc;}
</style>
<div class="new_excel">
<h1><?php echo $g5['title']?></h1>
<div class="excel_info">
<p>
엑셀파일을 저장하실 때는 <strong>Excel 97 - 2003 통합문서 (*.xls)</strong> 로 저장하셔야 합니다.
</p>
</div>
<form name="fitemexcelup" id="fitemexcelup" method="post" action="./excel_free_up2.php" enctype="MULTIPART/FORM-DATA" autocomplete="off">
<input type="hidden" name="bo_table" value="<?php echo $bo_table ?>">
<div id="excelfile_upload" style="text-align:center;">
<label for="excelfile">파일유형 선택</label>
<input type="radio" name="ex_type" value="1">신규파일
<input type="file" name="excelfile" id="excelfile">
</div>
<div class="btn_confirm01 btn_confirm">
<input type="submit" value="엑셀파일 등록" class="btn_submit">
<a href="<?php echo G5_BBS_URL?>/board.php?bo_table=<?php echo $bo_table?>" class="btn_submit" style="color:#FFF; text-decoration:none;">게시판 바로가기</a>
</div>
</form>
<div class="excel_desc">
<p class="excel_tit">엑셀 업로드 순서</p>
<ul>
<li class="excel_con">
<ul>
<li><p>1. 수정할 항목이 있는 게시판에서 엑셀을 다운로드 합니다.</p></li>
<li class="con_img"><img src="./img/excel.PNG" alt="엑셀 업로드 설명 1"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>2. 다운로드 한 엑셀 파일을 엽니다.<br>(안전하지 않을 수 있다는 팝업창이 나오면 '아니오'버튼을 클릭해주세요.)</p></li>
<li class="con_img"><img src="./img/excel2.PNG" alt="엑셀 업로드 설명 2"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>3. 내용을 추가 및 수정하고 다른 이름으로 저장 합니다.<br>(저장 버튼을 누른 후 통합 문서의 기능이 일부 손실될 수 있다는 팝업 창이 나오면 '아니오'버튼을 클릭해주세요.)</p></li>
<li class="con_img"><img src="./img/excel3.PNG" alt="엑셀 업로드 설명 3"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>4. 파일 이름은 원하시는 파일명으로 작성 후 파일 형식을 'Excel 97 - 2003 통합 문서 (*xls)로 저장해주세요.</p></li>
<li class="con_img"><img src="./img/excel4.PNG" alt="엑셀 업로드 설명 4"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>5. 저장 후 엑셀 업로드 페이지에서 신규파일 선택 후 파일선택 버튼을 눌러주세요.</p></li>
<li class="con_img"><img src="./img/excel5.PNG" alt="엑셀 업로드 설명 5"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>6. 파일선택에서 수정 및 추가한 엑셀파일을 업로드 합니다.</p></li>
<li class="con_img"><img src="./img/excel6.PNG" alt="엑셀 업로드 설명 6"></li>
</ul>
</li>
<li class="excel_con">
<ul>
<li><p>7. 파일명을 한번 더 확인하시고 엑셀파일 등록 버튼을 클릭합니다.</p></li>
<li class="con_img"><img src="./img/excel7.PNG" alt="엑셀 업로드 설명 7"></li>
</ul>
</li>
</ul>
</div>
</div>
<?
include_once(G5_PATH.'/_tail.php');
?>
excel_free_up2.php
<?php
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
?>
<?php
include_once('./_common.php');
if(!$_POST[ex_type]){
alert("파일유형을 선택해주세요");
}
// 상품이 많을 경우 대비 설정변경
set_time_limit ( 0 );
ini_set('memory_limit', '50M');
if(!$_FILES['excelfile']['tmp_name']) {
alert("등록하실 파일이 없습니다");
}
if($_FILES['excelfile']['tmp_name']) {
$file = $_FILES['excelfile']['tmp_name'];
include_once(G5_LIB_PATH.'/Excel/reader.php');
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('UTF-8');
/***
* if you want you can change 'iconv' to mb_convert_encoding:
* $data->setUTFEncoder('mb');
*
**/
/***
* By default rows & cols indeces start with 1
* For change initial index use:
* $data->setRowColOffset(0);
*
**/
/***
* Some function for formatting output.
* $data->setDefaultFormat('%.2f');
* setDefaultFormat - set format for columns with unknown formatting
*
* $data->setColumnFormat(4, '%.3f');
* setColumnFormat - set format for column (apply only to number fields)
*
**/
$data->read($file);
/*
$data->sheets[0]['numRows'] - count rows
$data->sheets[0]['numCols'] - count columns
$data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column
$data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell
$data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
$data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
$data->sheets[0]['cellsInfo'][$i][$j]['colspan']
$data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/
error_reporting(E_ALL ^ E_NOTICE);
$write_table = "g5_write_{$bo_table}";
for ($i = 2; $i <= count($data->sheets[0]["cells"]); $i++) { //$i == 몇번째 라인부터 등록할건지
$total_count++;
if($_POST[ex_type] == "2"){
$wr_1 = addslashes($data->sheets[0]['cells'][$i][2]); //필드1
$wr_2 = addslashes($data->sheets[0]['cells'][$i][3]); //필드2
$wr_3 = addslashes($data->sheets[0]['cells'][$i][4]); //필드3
$wr_4 = addslashes($data->sheets[0]['cells'][$i][5]); //필드4
$wr_5 = addslashes($data->sheets[0]['cells'][$i][6]); //필드5
$wr_6 = addslashes($data->sheets[0]['cells'][$i][7]); //필드6
$wr_7 = addslashes($data->sheets[0]['cells'][$i][8]); //필드7
$wr_8 = addslashes($data->sheets[0]['cells'][$i][9]); //필드8
$wr_9 = addslashes($data->sheets[0]['cells'][$i][10]); //필드9
$wr_10 = addslashes($data->sheets[0]['cells'][$i][11]); //필드10
$sql = " update {$write_table}
set wr_subject = '$wr_subject',
wr_1 = '$wr_1',
wr_2 = '$wr_2',
wr_3 = '$wr_3',
wr_4 = '$wr_4',
wr_5 = '$wr_5',
wr_6 = '$wr_6',
wr_7 = '$wr_7',
wr_8 = '$wr_8',
wr_9 = '$wr_9',
wr_10 = '$wr_10'
where wr_id = '$wr_id' ";
sql_query($sql);
}else{
$mb_id = $member['mb_id'];
$wr_name = $member['mb_nick'];
$wr_password = $member['mb_password'];
$wr_email = $member['mb_email'];
$wr_homepage = $member['mb_homepage'];
$wr_num = get_next_num($write_table);
$wr_reply = '';
$wr_1 = addslashes($data->sheets[0]['cells'][$i][1]); //필드1
$wr_2 = addslashes($data->sheets[0]['cells'][$i][2]); //필드2
$wr_3 = addslashes($data->sheets[0]['cells'][$i][3]); //필드3
$wr_4 = addslashes($data->sheets[0]['cells'][$i][4]); //필드4
$wr_5 = addslashes($data->sheets[0]['cells'][$i][5]); //필드5
$wr_6 = addslashes($data->sheets[0]['cells'][$i][6]); //필드6
$wr_7 = addslashes($data->sheets[0]['cells'][$i][7]); //필드7
$wr_8 = addslashes($data->sheets[0]['cells'][$i][8]); //필드8
$wr_9 = addslashes($data->sheets[0]['cells'][$i][9]); //필드9
$wr_10 = addslashes($data->sheets[0]['cells'][$i][10]); //필드10
$sql = " insert into $write_table
set wr_num = '$wr_num',
wr_reply = '$wr_reply',
wr_comment = 0,
ca_name = '$ca_name',
wr_option = '$html,$secret,$mail',
wr_subject = '$wr_subject',
wr_content = '$wr_subject',
wr_link1 = '$wr_link1',
wr_link2 = '$wr_link2',
wr_link1_hit = 0,
wr_link2_hit = 0,
wr_hit = 0,
wr_good = 0,
wr_nogood = 0,
mb_id = '$mb_id',
wr_password = '$wr_password',
wr_name = '$wr_name',
wr_email = '$wr_email',
wr_homepage = '$wr_homepage',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_last = '".G5_TIME_YMDHIS."',
wr_ip = '{$_SERVER['REMOTE_ADDR']}',
wr_1 = '$wr_1',
wr_2 = '$wr_2',
wr_3 = '$wr_3',
wr_4 = '$wr_4',
wr_5 = '$wr_5',
wr_6 = '$wr_6',
wr_7 = '$wr_7',
wr_8 = '$wr_8',
wr_9 = '$wr_9',
wr_10 = '$wr_10'";
sql_query($sql);
$wr_id = sql_insert_id();
// 부모 아이디에 UPDATE
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");
// 새글 INSERT
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$wr_id}', '{$wr_id}', '".G5_TIME_YMDHIS."', '{$mb_id}' ) ");
// 게시글 1 증가
sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}'");
}//type end
}//for end
alert("업로드 되었습니다",G5_BBS_URL."/board.php?bo_table=notebook");
}
?>
답변 2
Undefined constant "ex_type" 상수가 없습니다. 해당 상수 어디에 있나요?
if(!$_POST['ex_type']){ << 오타 난거 같아요 콤마 넣어주세요
말그대로 ex_type 상수가 정의되지 않아서 그렇습니다.
excel_free_up2.php 8번라인 채크해보세요.
답변을 작성하시기 전에 로그인 해주세요.