What are common functions in PHP for opening directories and listing files?

To open directories and list files in PHP, you can use the opendir() function to open a directory, readdir() function to read the directory contents, and closedir() function to close the directory handle once you're done. You can loop through the directory contents using a while loop until all files are listed.

$dir = "/path/to/directory";

// Open a directory handle
$handle = opendir($dir);

// Loop through the directory contents
while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
        echo "$file\n";
    }
}

// Close the directory handle
closedir($handle);