$photo_location = 'img/'; $unsorted = scandir($photo_location); for ($i = 2; $i < (count($unsorted)-1); $i++) { if (ereg("^field", $unsorted[$i])) $unsorted[$i] .= $files; }