게시판 첨부파일 선택 해서 다운로드 하기.
급하게 만들어 적용 중인데 참고해서 개발 할실분 있나 해서 올립니다.
게시판에서 선택한 게시물 첨부파일을 다운받을떄 사용 합니다.
[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개
arari
4년 전
유용한 정보를 공유해 주셔서 감사합니다.
4년 전
감사합니다.
1년 전
너무 유용한 팁 같은데 게시판 목록에서 버튼으로 적용하려면 어떻게 해야할까요? ㅠ
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4419 | ||
| 1974 |
그누x즁딩
|
4년 전 | 4075 | |
| 1973 | 4년 전 | 4337 | ||
| 1972 | 4년 전 | 7720 | ||
| 1971 |
|
4년 전 | 3760 | |
| 1970 | 4년 전 | 2843 | ||
| 1969 |
|
4년 전 | 3889 | |
| 1968 | 4년 전 | 4620 | ||
| 1967 | 4년 전 | 11976 | ||
| 1966 | 4년 전 | 2668 | ||
| 1965 | 4년 전 | 3267 | ||
| 1964 |
honbab
|
4년 전 | 2610 | |
| 1963 |
|
4년 전 | 3726 | |
| 1962 | 4년 전 | 2447 | ||
| 1961 | 4년 전 | 2918 | ||
| 1960 | 4년 전 | 3292 | ||
| 1959 |
welcome
|
4년 전 | 3279 | |
| 1958 |
|
4년 전 | 5202 | |
| 1957 | 4년 전 | 3566 | ||
| 1956 |
몰라무서워
|
4년 전 | 3265 | |
| 1955 | 4년 전 | 3510 | ||
| 1954 | 4년 전 | 3084 | ||
| 1953 | 4년 전 | 2537 | ||
| 1952 |
|
4년 전 | 4867 | |
| 1951 |
|
4년 전 | 3345 | |
| 1950 |
|
4년 전 | 4019 | |
| 1949 |
|
4년 전 | 3784 | |
| 1948 |
|
4년 전 | 3412 | |
| 1947 |
|
4년 전 | 3107 | |
| 1946 | 4년 전 | 5790 | ||
| 1945 | 4년 전 | 2846 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기