Created
September 10, 2014 08:38
-
-
Save cowboymathu/5f56e7a9dfa7ca25f223 to your computer and use it in GitHub Desktop.
Show images in directory recursively
This file contains hidden or 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 | |
/* | |
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