$handler = opendir("./"); while ($file = readdir($handler)) { if (preg_match("^.*\.JPG$^", $file)) { $i++; $pictures[$i] = readdir($handler); } }