Home  >  Article  >  Backend Development  >  opendir, readdir and closedir (PHP operating directories and files)_PHP tutorial

opendir, readdir and closedir (PHP operating directories and files)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:231054browse

opendir, readdir and closedir (PHP operating directories and files) This is a simple introductory tutorial for PHP directory and file operations. We mainly talk about the use of the three functions opendir, readdir and closedir. ​

opendir, readdir and closedir (php tutorial operating directories and files)
This is a simple introductory tutorial for PHP directory and file operations. We mainly talk about the use of three functions: opendir, readdir and closedir.
*/

$dir = "d:www.bkjia.com";

//Open the directory $dir and assign the directory handle to the variable $dh
if($dh = opendir($dir))
{
//Through the while loop, use the function readdir to get the file name
While(($file_name = readdir($dh)) !== false)
{
echo "file name: ".$file_name;
echo "
";
echo "
";
}
 
//After processing is completed, close the directory handle $dh
closedir($dh);
}

/*
opendir definition and usage
The opendir() function opens a directory handle and can be used by closedir(), readdir() and rewinddir().

If successful, this function returns a directory stream, otherwise it returns false and an error. You can hide error output by prepending "@" to the function name.

Grammar
opendir(path,context)


readdir definition and usage
The readdir() function returns the entry in the directory handle opened by opendir().

If successful, the function returns a file name, otherwise it returns false.

Grammar
readdir(dir_stream)

The closedir() function closes the directory handle opened by the opendir() function.

Grammar
closedir(dir_stream)


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445439.htmlTechArticleopendir, readdir and closedir (PHP operating directories and files) This is a simple PHP directory and file operation Introductory tutorial, we mainly talk about the use of three functions opendir, readdir and closedir...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn