2026, 새로운 도약을 시작합니다.

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

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

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

[code]

<?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];
}
?>

[/code]

----------

2. 함수의 사용

[code]

<?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번 일반파일 원이름
?>

[/code]

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

|

댓글 3개

스크랩 해갑니다. 고맙습니다.^

@웅프 감사합니다.

답변 달아주신 글 보고 왔는데 유용한 정보 얻어갑니다!! 엄지척 드리려했으나 1년이 지나서 못하네요ㅠ

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,598
2741 3일 전 조회 111
2740 4일 전 조회 103
2739 1주 전 조회 209
2738 1주 전 조회 217
2737 1주 전 조회 181
2736 1주 전 조회 280
2735 3주 전 조회 281
2734 3주 전 조회 263
2733 1개월 전 조회 265
2732 1개월 전 조회 301
2731 1개월 전 조회 267
2730 1개월 전 조회 226
2729 1개월 전 조회 356
2728 1개월 전 조회 245
2727 1개월 전 조회 422
2726 1개월 전 조회 256
2725 1개월 전 조회 330
2724 1개월 전 조회 358
2723 1개월 전 조회 267
2722 1개월 전 조회 300
2721 1개월 전 조회 211
2720 2개월 전 조회 304
2719 2개월 전 조회 307
2718 2개월 전 조회 202
2717 2개월 전 조회 336
2716 2개월 전 조회 202
2715 2개월 전 조회 311
2714 2개월 전 조회 273
2713 2개월 전 조회 376
2712 2개월 전 조회 289
🐛 버그신고