첨부파일 갯수 카운트

첨부파일 갯수 카운트

QA

첨부파일 갯수 카운트

본문

게시글의 첨부파일 개수에 따라 list에서 class를 다르게 주기 위한 코드를 짜고 있습니다.

파일 업로드 개수는 최대 4개이고, 4번째 첨부파일 슬롯에 파일을 업로드 했을때만 다른 클래스가 echo되는 코드입니다.

이미지 출력하는 부분에 아래처럼 코드를 작성했는데요.

 

이럴경우 파일을 4개 모두 업로드했을땐 full_files 클래스가 부여되는 것 처럼 보이는데

2번 첨부파일, 4번 첨부파일을 업로드 하게 되면 file count가 2가 아닌 4로 되어 있더라구요.

 

파일을 몇개 올리든간에 4번째 첨부파일에 업로드를 했다면 file count가 4가 됩니다.

1번 첨부파일, 3번 첨부파일 칸에만 업로드 했다면 3이 되구요.

파일 업로드 개수를 정확하게 카운트하는 코드가 있을까요?

 


<?php
if($list[$i]['file'][0]['file']){
    if($list[$i]['file']['count'] == 4){
        echo '<div class="img_wrap full_files">';
    }else{
        echo '<div class="img_wrap">';
    }
    echo $img_content;
}
if($list[$i]['file'][1]['file']){
    if($list[$i]['file']['count'] == 4){
        echo '<div class="img_wrap full_files">';
    }else{
        echo '<div class="img_wrap">';
    }
    echo $img_content2;
}
if($list[$i]['file'][2]['file']){
    if($list[$i]['file']['count'] == 4){
        echo '<div class="img_wrap full_files">';
    }else{
        echo '<div class="img_wrap">';
    }
    echo $img_content3;
}
if($list[$i]['file'][3]['file']){
    if($list[$i]['file']['count'] == 4){
        echo '<div class="img_wrap full_files">';
    }else{
        echo '<div class="img_wrap">';
    }
    echo $img_content4;
}
?>

이 질문에 댓글 쓰기 :

답변 3


$cnt = 0;
if ($list[$i]['file']['count']) {
    for ($j = 0; $j < 4; $j++) {
        if ($list[$i]['file'][$j]['source'])
            $cnt++;    
    }    
}
if ($cnt >= 4)
    echo '<div class="img_wrap full_files">';
else
    echo '<div class="img_wrap">';
    
echo $img_content;

skin/board/basic/list.skin.php 에서

$list['file']['count'] 를 정리하는 예제 입니다.

 


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
 
// ------------------------------------------------- added
//if ($board['bo_use_list_file'] == 1) {
array_walk($list, function (&$li) {
    for ($j = 0, $j_cnt = $li['file']['count']; $j < $j_cnt; $j++) {
        if (isset($li['file'][$j]) == true && empty($li['file'][$j]['source']) == true) {
            $li['file']['count'] -= 1;
        }
    }   
});
//}
// ------------------------------------------------- added
?>
<!-- 게시판 목록 시작 { -->
...

몇 버전 부터 있는건지는 모르겠는 wr_file 에 첨부파일 갯수가 있습니다 $list[$i]['wr_file'] 로 확인해보시면 될거 같습니다. 해당이 안되시면 $list[$i]['file']['count'] 로 한번 해보세요.

답변을 작성하시기 전에 로그인 해주세요.
전체 123,858 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT