From the course: Learning the Standard PHP Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Inspecting single directories with FilesystemIterator

Inspecting single directories with FilesystemIterator - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

Inspecting single directories with FilesystemIterator

- FilesystemIterator extends DirectoryIterator, so it's quite similar but it adds a number of improvements. I've copied filesystem.php from the Chapter 2 folder of the exercise files, and I've adjusted the path to the Common Images directory. Although we're going to be looking at FilesystemIterator, I'm going to begin with DirectoryIterator so we can see what the difference is. So let's load this page into a browser. We're not filtering out the files, so we've got also the dot files that represent the current and parent directories. And then we've got the names of all the files in the Images folder. So let's see what happens when we change that to FilesystemIterator. So if we just save that, and then refresh the browser. The dot files have gone, and instead of just the filename, we've got the relative path followed by the filename. Another important difference is that FilesystemIterator uses the path as the key, whereas DirectoryIterator uses a number. So let's just see that. So if we…

Contents