Home > Backend Development > PHP Tutorial > Usage of php directory traversal opendir() function

Usage of php directory traversal opendir() function

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

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

opendir() function example, code is as follows:

<?php  
$dir = "./"; 
 
// open a known directory, and proceed to read its contents  
if (is_dir($dir))  
{  
if ($dh = opendir($dir)) {  
while (($file = readdir($dh)) !== false) {  
echo "filename: $file : filetype: " . filetype($dir . $file) . "n"."<br />";  
}
closedir($dh);  
}  
}  
?>
Copy after login

The above is the detailed content of Usage of php directory traversal opendir() function. 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