바우보리

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

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

 

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

 

[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개

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

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

댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
21-11-23 조회 6,044
21-11-22 조회 7,233
21-11-19 조회 7,050
21-11-17 조회 7,588
21-11-14 조회 7,730
21-11-12 조회 6,864
21-11-10 조회 7,738
21-11-10 조회 8,260
21-11-09 조회 1.2만
21-11-09 조회 7,425
21-11-08 조회 6,416
21-11-06 조회 7,680
21-11-06 조회 8,399
21-11-01 조회 1.6만
21-10-31 조회 6,244
21-10-30 조회 7,147
21-10-23 조회 6,218
21-10-20 조회 7,519
21-10-16 조회 6,091
21-10-16 조회 6,645
21-10-14 조회 6,942
21-10-12 조회 6,999
21-10-08 조회 9,038
21-10-07 조회 7,098
21-10-05 조회 7,120
21-10-03 조회 7,178
21-10-02 조회 6,825
21-09-29 조회 6,163
21-09-28 조회 8,627
21-09-25 조회 7,043