+2  A: 

Some variation of the below is what i would use. YMMV depending on what youre doing. If you post your code we can address your specific implementation instead of jsut providing alternate solutions :-)

$dir = new DirectoryIterator('/path/to/states');
foreach($dir as $file)
{
  if(!$file->isDot() && $file->isFile() && strpos($file->getFilename(), '.txt') !== false)
  {
     $content = file_get_contents($file->getPathname());
     if($content)
     {
        // do your insert code
     }
  }
}
prodigitalson
Thanks! That solution did the trick. No variation was necessary other than plugging in my path... and I'll add my insert code.I guess, just for my own education purposes, I see that $file->getPathname());was something I'll have to read up on.
R Bennett
DirectoryIterator is one of the useful SPL classes added in php5. the `getPathname` method give you the full filesystem path to the file or directory in question `getFilename` give you jsut the file/dir name and `getPath` will get you just the path to the file/dir. Also if you used this as your solution can you mark this as the answer - or are you waiting for more technical details on whay your code doesnt work?
prodigitalson
+1 for using SPL.
Alix Axel
Yes, I can mark this as the answer - fairly new to the SO system so I wasn't sure how that worked. (and sorry for the delay in my responses I wasn't receiving any email notification of activity) If anyone wanted to add some info as to why the other method was failing I would find it useful but I wouldn't hold this open as unanswered for that.thank you again, I'm often in need of these type of answers for various projects and I'm finding Stack Overflow very useful.
R Bennett
Well ive very rarely made use of `readdir` but im thinking its probably an issue one of the values in your `$files` array. I suspect if you were to dump that you would see something unexpected. Or it could be that the error actually occurs in the `readdir` call and its an issue with perms on the dir/file. Normally if i were not using spl i would use `glob('/path/to/files/*.txt')` to get an array of files. In general, unless im dealing with a huge amount of data i try to avoid the functions that require manipulation of `resource` types directly.
prodigitalson