pdf파일첨부한 게시글

pdf파일첨부한 게시글

QA

pdf파일첨부한 게시글

그누보드5(영카트) 버전

5.6.15

사용 PHP 버전

8.2.12

본문

pdf파일을 첨부하고 쓴 게시글 전용 게시판의 목록에서 'pdf.js를 이용해서' 출력하고 싶습니다.

목록페이지에서는 설정에서 1개만 출력되도록 설정하구요.

 

<?php

 

if (isset($list[$i]['file'][0]['file'])) {

    $file_ext = pathinfo($list[$i]['file'][0]['file'], PATHINFO_EXTENSION);

    if (strtolower($file_ext) === 'pdf') {

        echo "<iframe src='".$plugin_dir."/pdf/web/viewer.php?file=".urlencode($attach_file)."' style='width:100%; height:700px; border:0;' scrolling=no></iframe>";

    }

} else {

    // 파일이 존재하지 않을 때 로그를 남깁니다.

    $log_message = "경고: 파일이 존재하지 않아 PDF 뷰어를 표시할 수 없습니다. 게시글 ID: " . $list[$i]['wr_id'];

    alert($log_message);

}

 

?>

이런 식은 아닌가죠?

 

 

이 질문에 댓글 쓰기 :

답변 3

<?php
if (isset($list[$i]['file'][0]['file']) && $list[$i]['file'][0]['file']) {

    $attach_file = $list[$i]['file'][0]['file']; 
    $file_ext = pathinfo($attach_file, PATHINFO_EXTENSION);

    if (strtolower($file_ext) === 'pdf') {
        echo "<iframe src='".$plugin_dir."/pdf/web/viewer.php?file=".urlencode($attach_file)."' style='width:100%; height:700px; border:0;' scrolling='no'></iframe>";
    }

} else {
    // 파일이 존재하지 않을 때 PHP 로그에 기록
    error_log("경고: 파일이 존재하지 않아 PDF 뷰어를 표시할 수 없습니다. 게시글 ID: " . $list[$i]['wr_id']);
}
?>

<?php
static $count = 0;
if ($count++ > 0) return;

foreach($list as $item) {
    $wr_id = $item['wr_id'];
    $sql = "SELECT * FROM {$g5['board_file_table']} WHERE bo_table='{$bo_table}' AND wr_id='$wr_id' ORDER BY bf_no";
    $result = sql_query($sql);
    while($file = sql_fetch_array($result)) {
        $ext = strtolower(pathinfo($file['bf_source'], PATHINFO_EXTENSION));
        if ($ext === 'pdf') {
            $file_url = G5_DATA_URL."/file/".$file['bo_table']."/".$file['bf_file'];
            echo "<div id='pdf-preview-{$wr_id}'></div>";
            echo "<script>
                const url = '{$file_url}';
                pdfjsLib.getDocument(url).promise.then(function(pdf) {
                    pdf.getPage(1).then(function(page) {
                        const canvas = document.createElement('canvas');
                        const context = canvas.getContext('2d');
                        const viewport = page.getViewport({ scale: 1.0 });
                        canvas.width = viewport.width;
                        canvas.height = viewport.height;
                        page.render({ canvasContext: context, viewport: viewport }).promise.then(function() {
                            document.getElementById('pdf-preview-{$wr_id}').appendChild(canvas);
                        });
                    });
                });
            </script>";
            break;
        }
    }
}
?>

테스트로 이렇게 호출을 해보시기 바랍니다.

내아이디 클릭해서 카톡주보세요 도와드릴게요

웅푸님 감사드립니다.
 

<?php

static $count = 0;

if ($count++ > 0) return;

 

foreach($list as $item) {

    $wr_id = $item['wr_id'];

    $sql = "SELECT * FROM {$g5['board_file_table']} WHERE bo_table='{$bo_table}' AND wr_id='$wr_id' ORDER BY bf_no";

    $result = sql_query($sql);

    while($file = sql_fetch_array($result)) {

        $plugin_dir_board = "/bbs/plugin" ;

        $ext = strtolower(pathinfo($file['bf_source'], PATHINFO_EXTENSION));

        if ($ext === 'pdf') {

            $file_url = G5_DATA_URL."/file/".$file['bo_table']."/".$file['bf_file'];

 

            // PDF.js 뷰어 iframe 삽입

            echo "<iframe src='".$plugin_dir_board."/pdf/web/viewer.php?file=".urlencode($file_url)."'

                     style='display:flex; width:100%; height:700px; border:0;'

                     scrolling='no'></iframe>";

 

            break; // 첫 번째 PDF만 출력

        }

    }

}

?>

위와 같이 해결했습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 1

회원로그인

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