Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of opendir function in php

Detailed explanation of the usage of opendir function in php

怪我咯
怪我咯Original
2017-07-06 10:23:422615browse

This article mainly introduces the usage of the opendir function in php. It details the usage of the opendir function to open a directory and related precautions in the form of examples. , has certain reference value, friends in need can refer to

This article analyzes the usage of the 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, return false. Take a look at opendir to list all file instances in the directory. The code is as follows:


The code is as follows:

$dirs ='./';//指定当前上当 
if( is_dir( $dirs ) ) 
{ 
 $hanld = opendir($dirs); 
 
 while (($file = readdir($hanld)) !== false) 
 { 
   echo "文件名: " . $file . "<br />"; 
 } 
 closedir($hanld); 
} 
else 
{ 
 echo &#39;不是目录&#39;; 
}

Output result:

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

Tips and comments:

Comments: Starting from PHP 5.0.0, the path parameter is supported ftp:// URL wrapper

Note: In PHP 4.3.0, the path parameter can be any URL that supports directory listing, but in PHP 4 there is only

file:// URL wrapper Support this feature.

The above is the detailed content of Detailed explanation of the usage of opendir function in php. For more information, please follow other related articles on the PHP Chinese website!

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