If you used ganeshXL’s code, you should be able to modify this regular expression to mean "if it starts with a ." to avoid the ., .. and .thumb... file entries.
if (ereg('^\.{1,2}$',$fn)) continue;
regex is not my strong point, but I know that can be done quite easily with the proper code. Maybe if you didn’t have the end-of-string symbol $ in the above expression? I believe as it is, it reads "begins and ends with 1 or 2 ."
^ is the "begins with" symbol, and trailing $ is the "ends with" symbol, while the .(1,2) means "one or two ."
So ’^\.’ should mean "begins with ." (the . has to be escaped since it’s a regex symbol itself), and should prevent processing of anything that starts with a period.
http://www.zend.com/zend/spotlight/code-gallery-wade5.php