TechniqueEither use the dir() function and manipulate the directory via a pseudo-object, or use the opendir() , readdir() , and closedir() functions to read the directory.
CommentsBoth solutions will work equally well; which one you choose is a matter of preference. The dir() function actually calls opendir() and creates an object that calls the corresponding functions in the second solution, so when you call $dh->read() , you are really calling readdir($dh) . As a matter of practice, I use the first solution just because I enjoy using the object interface. You might have noticed that the functions PHP offers are much like the C functions for manipulating directories. In fact, readdir() , rewinddir() , opendir() , and closedir() are simply wrappers for the C functions. |