Last active
August 29, 2015 14:13
-
-
Save cod3cow/7289a69ac670a8199f4c to your computer and use it in GitHub Desktop.
list all images of a folder with php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// list all images of a folder | |
$folder = 'images/'; | |
$types = array('png','jpg','jpeg','gif'); | |
$openfolder = opendir($folder); | |
while ($file = readdir($openfolder)) | |
{ | |
if( in_array(strtolower(substr($file,-3)),$types) OR | |
in_array(strtolower(substr($file,-4)),$types) ) | |
{ | |
$array[] = $file; | |
} | |
} | |
echo '<ul>'; | |
$number = count($array); | |
shuffle($array); | |
for($i=0; $i<$number; $i++) | |
{ | |
echo '<li><img src="'.$folder.$array[$i].'" /></li>'; | |
} | |
echo '</ul>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment