In this article, you will learn how to get the name of the next content present in the directory. The readdir() function in PHP returns the name of the next entry in a directory.
what is the syntax of the SCANDIR() function in php?
readdir(dir)
Parameter | Description |
---|---|
dir | Optional. Specifies the directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed |
examples of the SCANDIR() function
Example 1. In this example, we list all entries in the images directory, then close.
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>