Codice PHP:
function rec_scandir($dir)
{
   
$arrExtension = array(".txt",".php",".html",".doc");   
   
$files = array();
   if ( 
$handle opendir($dir) ) {
       while ( (
$file readdir($handle)) !== false ) {
           if ( 
$file != ".." && $file != "." ) {
               if ( 
is_dir($dir "/" $file) ) {
                   
$files[$file] = rec_scandir($dir "/" $file);
               }else {
                
$ext substr($file,strrpos($file,"."),strlen($file)); 
                if(
in_array($ext,$arrExtension))  
                   
$files[] = $file;
               }
           }
       }
       
closedir($handle);
       return 
$files;
   }

nell'array $files dovresti avere quello che vuoi...
Codice PHP:
$arrFilesImage rec_scandir("./"); 
print_r($arrFilesImage); 
sinc non l'ho provato,prova e fa sapere...