What are common methods for reading and displaying folder contents in PHP?
When working with files and folders in PHP, it is common to need to read and display the contents of a folder. This can be achieved using functions like scandir() to retrieve a list of files and directories in a folder, and then looping through this list to display the contents.
// Get the list of files and directories in a folder
$folderPath = 'path/to/folder';
$contents = scandir($folderPath);
// Loop through the contents and display them
foreach ($contents as $item) {
if ($item != '.' && $item != '..') {
echo $item . "<br>";
}
}