well, I'm lazy, and I made a bunch of typoes, but that should probably be written as
PHP Code:
while (false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
$files[] = $file;
}
}
notice the corrections, it's important :b
anyway, here's the breakdown : )
1: while (false !== ($file = readdir($handle)))
readdir($handle) returns the next file in the directory -- when there are none left, it evaluates to false and ends the while loop.
2: if($file != "." && $file != "..")
we're just checking here to make sure that the $file isn't . or .. which are both present in every folder and mean 'this folder' and 'parent folder'
3: $files[] = $file
throw the file into the array : )
If you have other directories in that directory it will cause problems -- you'll have to check if it's a directory using is_dir. If you're just looking for a certain kind of file, i.e. text files, replace the if conditional with this:
if (strtolower(substr($file, -4)) == ".txt")
that should hopefully take care of things for you ^_^