PHP readdir() Function

P
PHP scandir() Function
PHP opendir() Function

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)
ParameterDescription
dirOptional. Specifies the directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed
PHP scandir() method

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);
  }
}
?>
PHP scandir() Function
PHP opendir() Function

Add comment

Tutor Network

Share this

Learn PHP from A to Z