엑셀 업로드가 오류가 납니다..무엇이 문제인가요..?
본문
엑셀 업로드 시
신규파일에 파일을 첨부하면 페이지가 작동하지 않는다고 나오고
수정파일에 파일을 첨부하면 성공은 하는데, 엑셀에 작성해놓은 셀들이 나타나지 않습니다..
excel_up1.php
<?php
include_once("_common.php");
$g5['title'] = "엑셀 업로드";
include_once(G5_PATH.'/_head.php');
?>
<style>
.new_excel{border:3px solid #ccc; padding:0 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;}
</style>
<div class="new_excel">
<h1><?php echo $g5['title']?></h1>
<div class="excel_info">
<p>
엑셀파일을 저장하실 때는 <strong>Excel 97 - 2003 통합문서 (*.xls)</strong> 로 저장하셔야 합니다.
</p>
<p>
<a href="<?php echo $board_skin_url?>/0_hs_excel_0.xls">신규등록 엑셀파일 샘플 다운로드 Click</a>.
</p>
</div>
<form name="fitemexcelup" id="fitemexcelup" method="post" action="./excel_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="radio" name="ex_type" value="2">수정파일
<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>
<?
include_once(G5_PATH.'/_tail.php');
?>
excel_up2.php
<?php
include_once('./_common.php');
if(!$_POST[ex_type]){
alert("파일유형을 선택해주세요");
}
// 상품이 많을 경우 대비 설정변경
set_time_limit ( 0 );
ini_set('memory_limit', '50M');
ini_set('upload_max_filesize', '80M');
ini_set('post_max_size', '80M');
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 <= $data->sheets[0]['numRows']; $i++) { //$i == 몇번째 라인부터 등록할건지
$total_count++;
if($_POST[ex_type] == "2"){
$wr_id = addslashes($data->sheets[0]['cells'][$i][2]); //wr_id
$date = addslashes($data->sheets[0]['cells'][$i][3]); //date
$wr_subject = addslashes($data->sheets[0]['cells'][$i][4]); //필드1
$wr_1 = addslashes($data->sheets[0]['cells'][$i][5]); //필드1
$wr_2 = addslashes($data->sheets[0]['cells'][$i][6]); //필드2
$wr_3 = addslashes($data->sheets[0]['cells'][$i][7]); //필드3
$wr_4 = addslashes($data->sheets[0]['cells'][$i][8]); //필드4
$wr_5 = addslashes($data->sheets[0]['cells'][$i][9]); //필드5
$wr_6 = addslashes($data->sheets[0]['cells'][$i][10]); //필드6
$wr_7 = addslashes($data->sheets[0]['cells'][$i][11]); //필드7
$wr_8 = addslashes($data->sheets[0]['cells'][$i][12]); //필드8
$wr_9 = addslashes($data->sheets[0]['cells'][$i][13]); //필드9
$wr_10 = addslashes($data->sheets[0]['cells'][$i][14]); //필드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_subject = addslashes($data->sheets[0]['cells'][$i][2]); //필드1
$wr_1 = addslashes($data->sheets[0]['cells'][$i][3]); //필드1
$wr_2 = addslashes($data->sheets[0]['cells'][$i][4]); //필드2
$wr_3 = addslashes($data->sheets[0]['cells'][$i][5]); //필드3
$wr_4 = addslashes($data->sheets[0]['cells'][$i][6]); //필드4
$wr_5 = addslashes($data->sheets[0]['cells'][$i][7]); //필드5
$wr_6 = addslashes($data->sheets[0]['cells'][$i][8]); //필드6
$wr_7 = addslashes($data->sheets[0]['cells'][$i][9]); //필드7
$wr_8 = addslashes($data->sheets[0]['cells'][$i][10]); //필드8
$wr_9 = addslashes($data->sheets[0]['cells'][$i][11]); //필드9
$wr_10 = addslashes($data->sheets[0]['cells'][$i][12]); //필드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 = mysql_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=".$bo_table);
}
?>
excel_up3.php
<?php
include_once('./_common.php');
// 상품이 많을 경우 대비 설정변경
set_time_limit ( 0 );
ini_set('memory_limit', -1);
ini_set('upload_max_filesize', '80M');
ini_set('post_max_size', '80M');
R
$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($board_skin_path."/0_hs_excel_0.xls");
/*
$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 <= $data->sheets[0]['numRows']; $i++) { //$i == 몇번째 라인부터 등록할건지
$total_count++;
$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_subject = addslashes($data->sheets[0]['cells'][$i][2]); //필드1
$wr_1 = addslashes($data->sheets[0]['cells'][$i][3]); //필드1
$wr_2 = addslashes($data->sheets[0]['cells'][$i][4]); //필드2
$wr_3 = addslashes($data->sheets[0]['cells'][$i][5]); //필드3
$wr_4 = addslashes($data->sheets[0]['cells'][$i][6]); //필드4
$wr_5 = addslashes($data->sheets[0]['cells'][$i][7]); //필드5
$wr_6 = addslashes($data->sheets[0]['cells'][$i][8]); //필드6
$wr_7 = addslashes($data->sheets[0]['cells'][$i][9]); //필드7
$wr_8 = addslashes($data->sheets[0]['cells'][$i][10]); //필드8
$wr_9 = addslashes($data->sheets[0]['cells'][$i][11]); //필드9
$wr_10 = addslashes($data->sheets[0]['cells'][$i][12]); //필드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 = mysql_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}'");
}//for end
alert("업로드 되었습니다",G5_BBS_URL."/board.php?bo_table=".$bo_table);
?>
무엇이문제일까요..?ㅠㅠㅠㅠ..
도움부탁드립니다..개발자분이없어서 디자이너인 제가 하려니 어렵네요..
!-->!-->!-->답변 3
1) excel_up2.php 원래 파일로 교체하기 (에러 표시내용 확인 코드 추가 ini_set("display_errors", 1); )
2) excel_up1.php 상단 include_once(G5_PATH.'/_head.php'); 다음라인에 다음 코드 추가
$bo_table = "[게시판 ID]";
게시판 ID 부분에는 실제로 업로드하고자 하는 게시판의 ID 를 입력해야 됩니다. ex. $bo_table = "notice";
=> 확인
excel_up2.php 상단에
ini_set("display_errors", 1);
코드를 추가하면 500 에러의 상세내용이 표시됩니다. (include_once('./_common.php'); 코드 다음 라인)
해당 에러 내용을 알려주시는 것이 좋을 것 같습니다.
https://sir.kr/qa/405998?stx=.htaccess&sst=wr_num&unanswered=0&s_tag=
에러 표시하는 방법 참고하세요.
echo $sql;
sql_query($sql);
이렇게 해서 나온 sql 문자열을 알려 주세요. sql 문장에 오류가 있는 듯합니다.
또는
sql_query($sql, true);
이렇게 해 보시고
오류를 확인할 때는 마지막에 alert()는 주석 처리하세요.