scandir无法正常运行php

Does any one know how to scan directory recursively in php ?

$fileslist = array();

function readRecursive($dirname) {
   global $fileslist;
   $dir = scandir($dirname);

    foreach ($dir as $f) {
      if($f != "." && $f != ".." && $f != ".DS_Store") {
         if(is_dir($dirname.DIRECTORY_SEPARATOR.$f)) {
            $dname = $dirname.DIRECTORY_SEPARATOR.$f;
            readRecursive($dname);
         } else {
            $fileslist[] = $dirname.DIRECTORY_SEPARATOR.$f;
         }
      }
   }
}

following code doesn't work any idea Thanks in advance

First check it your php version. this function is available only above php 5.0