게시판 첨부파일 선택 해서 다운로드 하기. > 그누보드5 팁자료실

그누보드5 팁자료실

게시판 첨부파일 선택 해서 다운로드 하기. 정보

게시판 첨부파일 선택 해서 다운로드 하기.

본문

급하게 만들어 적용 중인데 참고해서 개발 할실분 있나 해서 올립니다.

 

게시판에서 선택한 게시물 첨부파일을 다운받을떄 사용 합니다.

 



<?php
include_once ('../../../../../common.php');

$bo_table = $_POST['bo_table'];

$count = count($_POST['chk_wr_id']);

if(!$count) {
    alert('항목을 하나 이상 선택하세요.');
}

$orgfilepath = G5_DATA_PATH.'/file/'.$bo_table.'/';
$zipName = "압축파일명".date("ymdhms", time()).".zip";
$zipfilepath = $orgfilepath.$zipName;
$zip = new ZipArchive();
if (!$zip->open($zipfilepath, ZipArchive::CREATE)) {
    exit("error");
}

$tmpFile_array = array();
$tmp_array = array();
$tmp_array = $_POST['chk_wr_id'];

$chk_count = count($tmp_array);
for ($i=0; $i<$chk_count; $i++) {

    //첨부파일 정보 확인.
    $sql = " select a.*, date_format(b.wr_datetime, '%Y%m%d%H%i%s') as wr_datetime, b.wr_1, b.wr_name, b.wr_subject from {$g5['board_file_table']} a
                inner join {$g5['write_prefix']}free b on b.wr_id = a.wr_id
              where a.bo_table = '$bo_table' and a.wr_id = '$tmp_array[$i]' ";
    $file = sql_query($sql);

    for ($j=0; $row=sql_fetch_array($file); $j++) {

        if (!$row['bf_file']) {
            alert('게시물번호 '.$row['wr_id'].' 파일 정보가 존재하지 않습니다.');
        }

        //첨부파일 존재 확인.
        $filename = $row['bf_file'];
        $filepath = addslashes($orgfilepath.$filename);
        $file_exist_check = (!is_file($filepath) || !file_exists($filepath)) ? false : true;
        $ext = pathinfo($filepath, PATHINFO_EXTENSION);

        if ( $file_exist_check != "1" ){
            alert('게시물번호 '.$row['wr_id'].' 파일이 존재하지 않습니다.');
        }

        $zip->addFile($filepath, $row['bf_source']);
     }
}
$zip->close();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$zipName");
header("Content-Transfer-Encoding: binary");
readfile($zipfilepath);
?>

 

추천
5

댓글 3개

전체 5 |RSS

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT