Recursively Loop Over a Directory in PHP using RecursiveDirectoryIterator

You can use PHP’s built in directory iterator (in php 5 or 7) to loop over a directory and perform operations on the files easily. This code is also checking to make sure that $file is indeed a file with the isFile() method.