게시판 첨부파일 선택 해서 다운로드 하기. 정보
게시판 첨부파일 선택 해서 다운로드 하기.본문
급하게 만들어 적용 중인데 참고해서 개발 할실분 있나 해서 올립니다.
게시판에서 선택한 게시물 첨부파일을 다운받을떄 사용 합니다.
<?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
5
댓글 3개
유용한 정보를 공유해 주셔서 감사합니다.
감사합니다.
너무 유용한 팁 같은데 게시판 목록에서 버튼으로 적용하려면 어떻게 해야할까요? ㅠ