I'm attempting to list only jpg files in a directory. There's over 200, but using the code below, only about 100 get listed. I've tried different variations for extracting the file extension, but this has been the only one that's worked: $sub = substr($file, -3);
Can anyone tell me why all of the files are not showing up?
Complete source:
<?php
require('index.inc');
$page = new buildpage();
$page->buildHeader();
$currentdir = '/home/tim/Documents/Web/';
$dir = opendir($currentdir);
echo "<ol>";
while ($file = readdir($dir)){
$file = readdir($dir);
$sub = substr($file, -3);
$ext = "jpg";
if (strcasecmp($sub, $ext) == 0) {
echo "<li>$file</li>";
}
}
echo "</ol>";
?>