Skip to content

Instantly share code, notes, and snippets.

@enijar
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enijar/11110429 to your computer and use it in GitHub Desktop.
Save enijar/11110429 to your computer and use it in GitHub Desktop.
List all images in a directory recursively.
<?php
function list_all_images($path)
{
$array = array();
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);
foreach($files as $name => $file) {
if(preg_match('/image.*/',finfo_file($finfo, $file))) {
array_push($array, $name);
}
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment