From the course: Learning the Standard PHP Library

Unlock the full course today

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

Getting information about files with SplFileInfo

Getting information about files with SplFileInfo - PHP Tutorial

From the course: Learning the Standard PHP Library

Start my 1-month free trial

Getting information about files with SplFileInfo

- Using an SPL Iterator to diverse the file system, gives you immediate access to a wealth of information about each file through the SPL file info class. This is fileinfo.php, which you can find in the Chapter 2 folder of the exercise files. It uses File System Iterator, to loop over the contents of the common images directory. I've also set the Unix Paths constent to display the directory separator on Windows as forward slashes. So, let's see this in a browser. It displays the relative path of every file in the directory. As explained earlier in this chapter, this value is being displayed by the two string method of the object that represents the current element in the four reach loop. In the case of File System Iterator and Recursive Directory Iterator, this is an instances of the SPL file info class. It's a different class in Directory Iterator, but it inherits from SPL file info, so the methods (disposes) are identical. So, let's explore some of those methods by going back to the…

Contents