Skip to content

Instantly share code, notes, and snippets.

@Restoration
Created June 16, 2016 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Restoration/e242a0cc5261c79a126b8ad466a39959 to your computer and use it in GitHub Desktop.
Save Restoration/e242a0cc5261c79a126b8ad466a39959 to your computer and use it in GitHub Desktop.
PHPでjpgもしくはpngを取得して画像を表示
<ul>
<?php
//画像をループするよ(´・ω・`)
//ディレクトリ取得
$img_fld = 'image/product/'.$_REQUEST['name']. '/';
//ディレクトリ内の一覧を取得する
$img_list = scandir($img_fld);
//フォルダ内の画像の数を取得する
$count = count($img_fld);
//画像を表示させるよ!
for($i=0; $i < $count; i++){
$file = pathinfo($img_list[$i]);
$file_name = $file["basename"];
$file_ext = $file['extension'];
//拡張子がpng,もしくはPNGなら表示、もしdbが取得されたら拒否
if(($file_ext == ('png' or 'PNG' )) and ($file_ext !='db')){
echo '<li>';
echo '<img src="'.$img_fld.$file_name.'">';
echo '</li>';
}
}
?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment