바우보리

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

· 2021-10-02 (토) 17:48:48 · 6528 · 3

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

 

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

 

[code]

<?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);
?>

[/code]

 

|

댓글 3개

유용한 정보를 공유해 주셔서 감사합니다.
감사합니다.

너무 유용한 팁 같은데 게시판 목록에서 버튼으로 적용하려면 어떻게 해야할까요? ㅠ

댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,790건
+
제목 글쓴이 날짜 조회
21-11-23 조회 5,759
21-11-22 조회 6,935
21-11-19 조회 6,723
21-11-17 조회 7,297
21-11-14 조회 7,403
21-11-12 조회 6,589
21-11-10 조회 7,458
21-11-10 조회 7,951
21-11-09 조회 1.2만
21-11-09 조회 7,148
21-11-08 조회 6,138
21-11-06 조회 7,404
21-11-06 조회 8,134
21-11-01 조회 1.6만
21-10-31 조회 5,957
21-10-30 조회 6,857
21-10-23 조회 5,946
21-10-20 조회 7,233
21-10-16 조회 5,817
21-10-16 조회 6,377
21-10-14 조회 6,669
21-10-12 조회 6,731
21-10-08 조회 8,752
21-10-07 조회 6,815
21-10-05 조회 6,845
21-10-03 조회 6,906
21-10-02 조회 6,529
21-09-29 조회 5,883
21-09-28 조회 8,355
21-09-25 조회 6,754