채택완료

게시판 리스트에서  첨부한 파일 여러개 출력

2024-07-08 (월) 23:25:13 4,639

게시판 리스트에서  첨부한 파일을 출력하고 싶습니다.

pdf, doc 등등 파일을 여러개 첨부했을때

리스트에서 파일확장자에 맞게 아이콘으로 노출되고  아콘을 클릭하면 다운로드 되게 하고 싶습니다.

https://gnustudy.com/bbs/board.php?bo_table=skin_board&wr_id=91

위 소스를 참고하였는데 파일 한개만 노출이 되네요.

|

답변 2개

채택된 답변
+20 포인트
2024-07-09 (화) 00:53:20

<?php echo $list[$i]['file'][0]['href']; ?> 이거는 배열의 0번째 즉 첫번째를 말합니다, 다른것도 하려면 <?php echo $list[$i]['file'][$i]['href']; ?> 이렇게 해야 할것이며 ....

해결하였습니다.

다른분들께서도 궁금하실듯하여 소스 남겨놓습니다.

Copy
<?php

$allowed_extensions = array("pdf", "hwp", "doc", "xls", "ppt", "zip", "txt", "jpg", "avi", "psd", "mp3");

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

foreach ($list[$i]['file'] as $file) {

if (isset($file['source']) && isset($file['href'])) {

$file_ext_name = strtolower(substr(str_replace(".", "", substr($file['source'], -4)), 0, 3));

if (in_array($file_ext_name, $allowed_extensions)) {

$file_ext = "$board_skin_url/img/icon_" . $file_ext_name . ".png";

} else {

$file_ext = "$board_skin_url/img/icon_file.png";

}

echo "<a href='" . $file['href'] . "'><img src='$file_ext' border='0' align='absmiddle'></a>";

}

}

}

?>

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