I am creating photo gallery using readdir , in that directory there are non image file also . There are several thousands files in the directory , i am really struggling to filter the extension . Any help will be appreciated
if ($handle = opendir(getcwd())) {
while (false !== ($entry = readdir($handle))) {
//but there are other files like doc,pdf,html,php how to fiter them
echo "<img src='$entry' height='100' width='100'>";
}
closedir($handle);
}
Try the glob()
function, which allows wildcards for filenames much as you can directly on the command line. e.g.
$files = glob('*.jpg');
foreach($files as $file) {
echo ....
}