Skip to content

Instantly share code, notes, and snippets.

@schmidt1024
Last active August 29, 2015 14:13
Show Gist options
  • Save schmidt1024/7289a69ac670a8199f4c to your computer and use it in GitHub Desktop.
Save schmidt1024/7289a69ac670a8199f4c to your computer and use it in GitHub Desktop.
list all images of a folder with php
<?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