채택완료

엑셀 다운로드 시 에러

2019-08-11 (일) 15:16:16 4,308

안녕하세요.

게시판에서 여분필드와 제목, 내용등을 취합해서 다운로드하는데 갑자기 시 에러가 나서 질문드립니다.

기존의 환경에서는 모두 다운로드가 잘 됬는데, 서버 이전 이후 엑셀 다운로드 부분만 에러가 납니다.

기존의 환경은 mariadb-10.0.x (UTF-8) / php7.3 입니다.

에러는 아래와 같이 나오며, 변경된 환경은 PHP7.0 / mysql5.7 입니다.

3531151019_1565504144.8939.png

엑셀 php 코드 전문입니다

Copy
<?php
include_once('./_common.php');

$csv = 'xls';

// MS엑셀 XLS 데이터로 다운로드 받음
if ($csv == 'xls')
{
    
    if($_GET[stx]){ 
        $searches .= "and (wr_subject = '{$_GET[stx]}' or wr_content = '{$_GET[stx]}' or wr_1 = '{$_GET[stx]}' or wr_2 = '{$_GET[stx]}' or wr_3 = '{$_GET[stx]}'  or wr_3 = '{$_GET[stx]}'  or wr_3 = '{$_GET[stx]}')";
    }
    
    if($_GET[fr_date] && $_GET[to_date]){

        $fr_date_a = $_GET[fr_date]." 00:00:00";
        $to_date_a = $_GET[to_date]." 23:59:59";

        $searches .= "and (wr_datetime between '{$fr_date_a}' and '{$to_date_a}') ";
    }

    $sql = " SELECT * FROM g5_write_{$bo_table} where wr_is_comment = '0' {$searches}";
    $result = sql_query($sql);
    $cnt = sql_num_rows($result); 
    if (!$cnt)
        alert("출력할 내역이 없습니다.");

    /*================================================================================
    php_writeexcel http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/
    =================================================================================*/

    include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_workbook.inc.php');
    include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php');

    $fname = tempnam(G5_DATA_PATH, $board.".xls");
    $workbook = new writeexcel_workbook($fname);
    $worksheet = $workbook->addworksheet();

    // Put Excel data
    $data = array('신청번호','신청날짜','실명','필드1','필드2','필드3','필드4','필드5','필드6','필드7','필드8','필드9','필드10');
    $data = array_map('iconv_euckr', $data);

    $col = 0;
    foreach($data as $cell) {
        $worksheet->write(0, $col++, $cell);
    }


    for($i=1; $row=sql_fetch_array($result); $i++)
    {
        $row = array_map('iconv_euckr', $row);
        
        $up_date = date("20y-m-d", strtotime($row['wr_datetime']));
         $worksheet->write($i, 0, $i);
         $worksheet->write($i, 1, $up_date);
         $worksheet->write($i, 2, $row['wr_subject']);
         $worksheet->write($i, 3, $row['wr_1']);
         $worksheet->write($i, 4, $row['wr_2']);
         $worksheet->write($i, 5, $row['wr_3']);
         $worksheet->write($i, 6, $row['wr_4']);
         $worksheet->write($i, 7, $row['wr_5']);
         $worksheet->write($i, 8, $row['wr_6']);
         $worksheet->write($i, 9, $row['wr_7']);
         $worksheet->write($i, 10, $row['wr_8']);
         $worksheet->write($i, 11, $row['wr_9']);
         $worksheet->write($i, 12, $row['wr_10']);
    }

    $workbook->close();
    
    header("Content-charset=utf-8");
    header("Content-Type: application/x-msexcel; name=\"{$bo_table}-".date("ymd", time()).".xls\"");
    header("Content-Disposition: inline; filename=\"{$bo_table}-".date("ymd", time()).".xls\"");
    $fh=fopen($fname, "rb");
    fpassthru($fh);
    unlink($fname);

    exit;
}

if (mysql_num_rows($result) == 0)
{
    echo "<script>alert('출력할 내역이 없습니다.'); window.close();</script>";
    exit;
}
?>

귀중한 시간 내어주시어 답변해주시는 분들에게 감사합니다..

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

웹서버의 에러로그 파일을 살펴 보시기 바랍니다. 

답변에 대한 댓글 1개

2019-08-11 (일) 16:38:46
확인해보니 7.0 이상부터는 sql문에 '' 를 써줘야 하더군요..

답변감사드립니다.

답변을 작성하려면 로그인이 필요합니다.