채택완료

특정확장자들만 이미지 보이게 하기

현재 

Copy
<?php for($j = 0; $j <= count($list[$i]['file'])-2; $j++) {?>
<img src="<?=$list[$i]['file'][$j]["path"]."/".$list[$i]['file'][$j]["file"];?>">
<?php } ?>

로 해서 첨부한 파일을 리스트에서 이미지로 전부 노출하고 있습니다.

이중에 png, jpg, gif 확장자로된 첨부파일만 노출하려고 하는데 어떻게 해야 할까요?

답변 4개

채택된 답변
+20 포인트

Copy
<?php 
for($j = 0; $j <= count($list[$i]['file'])-2; $j++) {
    if(preg_match("/\.(gif|jpg|jpeg|png)$/i", $list[$i]['file'][$j]["file"])) { 
?>
    <img src="<?=$list[$i]['file'][$j]["path"]."/".$list[$i]['file'][$j]["file"];?>">
<?php 
    }
} 
?>

이렇게 하면 될거같아보이는데요

모두 답변감사합니다. : )

$list[$i]['file'][$j] 에 bf_type이 담겨 있을겁니다.

Copy
<?php for($j = 0; $j <= count($list[$i]['file'])-2; $j++) {?>
<?php if($list[$i]['file'][$j]['bf_type'] < 4){ ?>
<img src="<?=$list[$i]['file'][$j]["path"]."/".$list[$i]['file'][$j]["file"];?>">
<?php } ?>
<?php } ?>

bf_type 1 => gif 2=> jpg 3 => png 입니다.

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