<?php
class files
{
private function check_ext($file, $correct)
{
$exp = explode('.', $file);
$exp = $exp[count($exp) - 1];
if($exp != $correct)
return false;
return true;
}
function count_files($directory, $extension)
{
if(!is_dir($directory))
die('La directory scelta è inesistente.');
$op = opendir($directory);
$count = 0;
while(false !== ($read = readdir($op)))
{
if($read == '.' || $read == '..')
continue;
if(is_dir("{$directory}/{$read}"))
$count += $this->count_files("{$directory}/{$read}", $extension);
elseif(file_exists("{$directory}/{$read}") && $this->check_ext($read, $extension))
$count += 1;
}
closedir($op);
return $count;
}
}
?>