//Create a new FilesystemIterator object $iterator = new FilesystemIterator('/path/to/folder/'); //Loop through all files in the folder and print their contents foreach($iterator as $file){ if($file->isFile()){ $contents = $file->getFile(); echo $contents; } }
//Create a new FilesystemIterator object $iterator = new FilesystemIterator('/path/to/folder/'); //Create a new array to store filenames $filenames = []; //Loop through all files in the folder and add their names to the array foreach($iterator as $file){ if($file->isFile()){ $filenames[] = $file->getFilename(); } } //Print the filenames print_r($filenames);This example demonstrates how to use the getFile method to get the filenames of each file in a folder and add them to an array. Based on the use of the FilesystemIterator class and the SPL extension, the package library for this method would be the SPL package in PHP.