PHP closedir() Function

PHP dir() Function
PHP chdir() Function

In this article, you will learn how to close an opened directory in PHP. The closedir() function in PHP closes a directory handle.

what is the syntax of the CLOSEDIR() function in php?

closedir(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 CLOSEDIR() method

examples of the CLOSEDIR() function

Example 1. In this example, we open a directory, read its contents, 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 dir() Function
PHP chdir() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top