Usage Example of opendir Function in php

  • 2021-08-03 09:49:23
  • OfStack

In this paper, the usage of opendir function in php is analyzed with examples. Share it for your reference. The details are as follows:

opendir Syntax: opendir (path, context)

Directory, Function Description: Open directory handle, opendir () function opens a directory handle, then the function returns a directory stream, otherwise return false. Look at an opendir list directory all file instances, code as follows:

$dirs ='./';// Specifies that you are currently fooled  
if( is_dir( $dirs ) )
{
 $hanld = opendir($dirs);
 
 while (($file = readdir($hanld)) !== false)
 {
   echo " Filename : " . $file . "<br />";
 }
 closedir($hanld);
}
else
{
 echo ' Not a directory ';
}

Output:
File name: a
File name: b
File name: www. ofstack. com

Tips and notes:

Note: Beginning with PHP 5.0. 0, path parameters support ftp://URL wrapper

Note: In PHP 4.3. 0, the path parameter can be any URL that supports directory listings, but in PHP 4 only file://URL wrapper supports this feature.

I hope this article is helpful to everyone's PHP programming.


Related articles: