그누보드 스킨

그누보드 다중파일다운로드(압축다운로드)

헤롱헤롱이 2021. 2. 16. 18:08

다중파일다운로드(압축다운로드).zip
0.00MB

 

//지정한 게시판의 모든게시글의 파일을 압축후 다운로드

 

사용법

 

라이브러리 압축 클래스 파일추가

 

//원하는게시판번호와 분류코드를 입력 분류코드가 없는경우 빈값을 전송

 

 

 

 

 

//list.skin.php

<?php if ($admin_href) { ?><li><a href="/bbs/zip_download.php?bo_table=<?= $bo_table ?>&sca=<?= $_GET["sca"] ?>" class="btn_design1" target="_blank">파일다운로드(<?= $_GET["sca"] ?>)</a></li><?php } ?>

//링크 추가

//분류별 파일을 다운로드

<?php
require 'cla_directzip.php';
$zip = new DirectZip();
$zip->open('브라우저로 보낼 압축파일 이름.zip');
$zip->addFile('/tmp/추가할 파일.jpg', '압축파일 내 파일 이름.jpg');
$zip->addEmptyDir('압축파일 내 폴더 이름'); // 안 해도 상관없음.
$zip->addFile('/tmp/추가할 파일2.png', '압축파일 내 폴더 이름/압축파일 내 파일 이름.png');
$zip->addFile('/tmp/추가할 파일3.jpg'); // 압축파일에 파일을 '추가할 파일3.jpg'로 추가
$zip->addFromString('바로 글쓰기.txt', '파일 내용'); // 압축파일에 '파일 내용'을 '바로 글쓰기.txt'로 추가
$zip->close();

?>

 

 

 

소스

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

// clean the output buffer
ob_end_clean();

$sca = $_GET["sca"];

if($sca)
{
    $sWhere = " WHERE ca_name = '{$sca}' ";
}

//게시판글 검색
$boardSql =" SELECT * FROM g5_write_{$bo_table} {$sWhere} ORDER BY wr_id ASC; ";
$boardRes = sql_query($boardSql);

include_once G5_LIB_PATH.'/cla_directzip.php';
$zip = new DirectZip();

$zip->open($sca.'.zip');
while($res = sql_fetch_array($boardRes))
{
    $sql = " select bf_source, bf_file from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$res["wr_id"]}' ";
    $file = sql_fetch($sql);
    
    if(!$file['bf_file'])
    {
        continue;        
    }
    
    $filepath = G5_DATA_PATH.'/file/'.$bo_table.'/'.$file['bf_file'];
    $filepath = addslashes($filepath);
    if (!is_file($filepath) || !file_exists($filepath))
    {
        continue;
    }
    
    $original = $file['bf_source'];
    
    $zip->addFile($filepath, $res["wr_id"]."-".$original);
    
}

$zip->close();
//게시글들의 모든파일을 읽어 압축후 해당파일을 다운로드 

?>