function print_image_list($startdir) { // read directory contents if (file is an image file) { // print it out or do what you want with the name } elseif (is directory other than . or ..) { print_image_list($this_directory); } }