$i = 1; while ($i <= 10) { // this section counts the number of photos up to 10 if (is_file("0".$i.".jpg")) { $amount = $i; } $i++; } ?>