테스트 사이트 - 개발 중인 베타 버전입니다

첨부파일 다운로드 유효기간 적용하기

· 8개월 전 · 498 · 2

첨부파일에 다운로드 유효기간을 적용할 수 있게 변경해봤습니다.

여분필드를 이용해서 숫자를 입력해주면 됩니다.

 

wirte.skin.php

[code]

    <?php if ($is_admin) { // 관리자만 보이도록 설정 ?>
    <tr>
        <th scope="row">다운로드 유효기간 (일)</th>
        <td>
            <input type="number" name="wr_1" value="<?php echo isset($write['wr_1']) ? $write['wr_1'] : '365'; ?>" class="frm_input" size="10"> 일
            <p class="frm_info">기본값: 365일 (비워두면 기본값 적용)</p>
        </td>
    </tr>
    <?php } else { ?>
        <input type="hidden" name="wr_1" value="<?php echo isset($write['wr_1']) ? $write['wr_1'] : '365'; ?>">
    <?php } ?>

[/code]

 

view.skin.php

첨부파일 부분 교체 157라인

[code]

<?php
// 가변 파일
for ($i=0; $i<count($view['file']); $i++) {
    if (isset($view['file'][$i]['source']) && $view['file'][$i]['source'] && !$view['file'][$i]['view']) {
        // 첨부파일 정보
        $file = $view['file'][$i];
        $file_name = $file['source'];
        $file_url = $file['href'];
        $file_size = $file['size'];
        $download_count = $file['download'];
        $upload_date = strtotime($file['datetime']); // 업로드 날짜
        
        // 여분필드1에서 유효기간(일) 가져오기 (기본값: 365일)
        $expire_days = isset($write['wr_1']) && is_numeric($write['wr_1']) ? intval($write['wr_1']) : 365;
        $expire_date = strtotime("+{$expire_days} days", $upload_date); // 설정된 기간 후 만료
        $remaining_days = ceil(($expire_date - time()) / 86400); // 남은 일수 계산

        // 툴팁 메시지 설정
        if ($remaining_days > 0) {
            $tooltip = "다운로드 유효기간이 {$remaining_days}일 남았습니다.";
        } else {
            $tooltip = "다운로드 기간이 만료되었습니다.";
        }

        // 다운로드 가능 여부 설정
        $disabled_class = ($remaining_days <= 0) ? 'disabled-link' : '';
        $disabled_attr = ($remaining_days <= 0) ? 'style="pointer-events: none; color: gray;"' : '';
?>
        <li>
            <i class="fa fa-folder-open" aria-hidden="true"></i>
            <a href="<?php echo ($remaining_days > 0) ? $file_url : '#'; ?>" 
               class="view_file_download <?php echo $disabled_class; ?>" 
               data-tooltip="<?php echo $tooltip; ?>" 
               <?php echo $disabled_attr; ?>>
                <strong><?php echo $file_name; ?></strong> <?php echo $file['content']; ?> (<?php echo $file_size; ?>)
            </a>
            <br>
            <span class="bo_v_file_cnt">
                <?php echo $download_count; ?>회 다운로드 | DATE : <?php echo $file['datetime']; ?>
            </span>
        </li>
<?php
    }
}
?>

[/code]

 

하단에 Javascript 추가

[code]

document.addEventListener("DOMContentLoaded", function () {
    const fileLinks = document.querySelectorAll(".view_file_download");

    fileLinks.forEach(link => {
        link.addEventListener("mouseover", function () {
            const tooltipText = this.getAttribute("data-tooltip");
            this.setAttribute("title", tooltipText);
        });
    });
});

[/code]

 

style.css 끝에 추가

[code]

/* 파일 다운로드 CSS */
.view_file_download {
    position: relative;
    text-decoration: none;
    color: #0078ff;
    cursor: pointer;
}

.view_file_download:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: 120%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    white-space: nowrap;
    font-size: 12px;
    z-index: 10;
}

.disabled-link {
    color: gray !important;
    pointer-events: none;
}
 

[/code]

댓글 작성

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

로그인하기

댓글 2개

8개월 전

감사합니다 ^^

8개월 전

감사합니다 

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168