Counting .jpgs in a directory

Hey, for my portfolio I need to be able to count the amount of .jps in a given directory for a nice display in flash. I’m pretty sure I’ve heard of a php way to do this, can someone help me out on the details of counting files in a directory then storing that number to a variable with php?

Or if its do-able in flash MX alone I’d rather use that method.