Skip to content

Instantly share code, notes, and snippets.

@cowboymathu
Created September 10, 2014 08:38
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 cowboymathu/5f56e7a9dfa7ca25f223 to your computer and use it in GitHub Desktop.
Save cowboymathu/5f56e7a9dfa7ca25f223 to your computer and use it in GitHub Desktop.
Show images in directory recursively
<?php
/*
Show images recursively in a directory v1.0
Author: Mathuvathanan Mounasamy
Licensed under the MIT license
*/
showImages('media/catalog/product/F');
function showImages($directory) {
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
$file_display = array('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF');
foreach ($scanned_directory as &$file) {
if (is_dir($directory."/".$file)) {
showImages($directory."/".$file);
} else {
$filen = explode(".", $file);
$ext = end($filen);
if (in_array($ext, $file_display)) {
echo '<img src="', $directory, '/', $file, '" alt="', $file, '" height="250" style="border: 3px solid #FFF" />';
} else {
}
}
}
unset($file);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment