if you want a smaller and more flexible solution, put this at the end of your file:
<?PHP
function count_files($extension, $directory = "./", $depth = 0) {
static $fileCount = 0;
$handle = opendir($directory);
if (!is_resource($handle)) return(0);
while (false !== ($file = readdir($handle))) {
$fullPath = "$directory/$file";
if ((is_dir($fullPath) || is_link($fullPath)) && ($file != "." && $file != "..")) {
count_files($extension, $fullPath, $depth + 1);
} else if ((strtolower(substr($file, -strlen($extension))) == "$extension")) {
$fileCount++;
}
}
closedir($handle);
return $fileCount;
}
?>
And then just put this where you want your count to show up:
<?PHP echo count_files(".jpg"); ?>
Just put whatever extension you want in place of .jpg to get other counts. This function also checks in subdirectories and can optionally look in any directory. Maybe this will be more useful to you. 🙂