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

pdf파일첨부한 게시글

ubplus 2개월 전 조회 287

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개

u
2개월 전

웅푸님 감사드립니다.
 

<?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만 출력

        }

    }

}

?>

위와 같이 해결했습니다.

로그인 후 평가할 수 있습니다

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

웅푸
2개월 전

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

u
ubplus
2개월 전
답변 감사해요. 하지만.... 작동하지 않습니다.
웅푸
2개월 전
<?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;
}
}
}
?>

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

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

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

들레아빠
2개월 전
로그인 후 평가할 수 있습니다

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

답변을 작성하려면 로그인이 필요합니다.

로그인