Home > Backend Development > PHP Tutorial > Simple usage instructions for the opendir function in php?

Simple usage instructions for the opendir function in php?

怪我咯
Release: 2023-03-13 12:36:02
Original
1461 people have browsed it

opendir() FunctionOpen a directory handle. If successful, the directory handle resource is returned. Returns FALSE on failure. If the path is not a legal directory, or the directory cannot be opened due to licensing restrictions or filesystem errors, an E_WARNING level error is thrown. You can hide the error output of opendir() by adding '@' before the function name

opendir() function syntax

opendir(path,context);
Copy after login
Parameters Description
pathRequired. Specifies the directory path to be opened.
context Optional. Specifies the environment for directory handles. context is a set of options that modify the behavior of a directory stream.

opendir() function example, 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;; 
}
Copy after login

Output result:
File name: a
File name: b
File name:www.php.cn

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template