write, view 공통 첨부파일 총개수, 경로, 이름을 추출하는 함수 > 그누보드5 팁자료실

그누보드5 팁자료실

write, view 공통 첨부파일 총개수, 경로, 이름을 추출하는 함수 정보

write, view 공통 첨부파일 총개수, 경로, 이름을 추출하는 함수

본문

 

이건 제가 필요에 의해 함수로 만들어 보았는데... 같이 공유합니다.

 

1. write.skin.php 또는 view.skin.php 에서 필요한 곳에 함수 생성


<?php
$wv_mode = $view ? $view : $file;
$wv_yes = $view ? "view_yes" : "write_yes";
function file_attach(...$attach) {
    global $wv_mode, $wv_yes;
    $wv_file = $wv_yes == "write_yes" ? $wv_mode : $wv_mode['file'];  
    $attach_files = [];
    for ($i = 0; $i < $wv_file['count']; $i++) {
        $attach_file = [$wv_file[$i]['path'].'/'.$wv_file[$i]['file'], $wv_file[$i]['source']];
        if ($attach[1] == "img") if ($wv_file[$i]['image_type'] > 0) array_push($attach_files, $attach_file);
        if ($attach[1] == "normal") if ($wv_file[$i]['image_type'] == 0) array_push($attach_files, $attach_file);
        if ($attach[1] == "all") array_push($attach_files, $attach_file);
    }
    return $attach[0] === "count" ? count($attach_files) : $attach_files[$attach[0] - 1][$attach[2] == "name" ? 1 : 0];
}
?>

 

----------

 

2. 함수의 사용


<?php
echo file_attach("count", "all"); // 첨부파일 총개수
echo file_attach("count", "img"); // 이미지파일 총개수
echo file_attach("count", "normal"); // 일반파일(이미지를 제외한 파일) 총개수
//-----
echo file_attach(1, "all"); // 1번 첨부파일 경로
echo file_attach(1, "img"); // 1번 이미지파일 경로
echo file_attach(1, "normal"); // 1번 일반파일 경로
//-----
echo file_attach(3, "all", "name"); // 3번 첨부파일 원이름
echo file_attach(3, "img", "name"); // 3번 이미지파일 원이름
echo file_attach(3, "normal", "name"); // 3번 일반파일 원이름
?>

"count" 를 제외한 숫자는 첨부파일의 순서입니다.

추천
5

댓글 3개

전체 2,431 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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