Home >Backend Development >PHP Tutorial >Usage examples of opendir function in php, phpopendir_PHP tutorial

Usage examples of opendir function in php, phpopendir_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:13:56961browse

Example of usage of opendir function in php, phpopendir

This article analyzes the usage of opendir function in PHP with examples. Share it with everyone for your reference. The details are as follows:

opendir syntax: opendir(path,context)

Directory, function description: open a directory handle, the opendir() function opens a directory handle, then the function returns a directory stream, otherwise it returns false. Let's look at an example of opendir listing all files in the directory. The code is as follows:

Copy code The code is as follows:
$dirs ='./';//Specify the current scammer
if( is_dir( $dirs ) )
{
$hanld = opendir($dirs);

while (($file = readdir($hanld)) !== false)
{
echo "File name: " . $file . "
";
}
closedir($hanld);
}
else
{
echo 'Not a directory';
}

Output result:
File name:a
File name: b
File name: www.jb51.net

Tips and Notes:

Note: Starting from PHP 5.0.0, the path parameter supports ftp:// URL wrapper

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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912286.htmlTechArticleExamples of usage of opendir function in php, phpopendir This article analyzes the usage of opendir function in php. Share it with everyone for your reference. The details are as follows: opendir syntax: opendir(path,context) object...
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