Excuse the formating in this code, I'm typing this directly into the browser, and tab does not work.
$dirhandle = opendir ("/path/");
while (($filehandle = readdir($dirhandle)) !== false) //This will cause the program to loop until all files and directories are read from the dir
{
if (!is_dir ($filehandle) //Make sure that we're only counting files
{
$count++;
echo "a href='java script:changePhoto($count)'><img src='$id/$count.jpg' width='45' height='45' hspace='2' border='0' alt=></a>";
}
}