pdf파일첨부한 게시글
본문
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)) {
$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만 출력
}
}
}
?>
위와 같이 해결했습니다.