Home > Backend Development > PHP Tutorial > Usage example of php directory traversal function opendir, phpopendir_PHP tutorial

Usage example of php directory traversal function opendir, phpopendir_PHP tutorial

WBOY
Release: 2016-07-13 10:13:24
Original
1120 people have browsed it

PHP directory traversal function opendir usage example, phpopendir

The example in this article describes the usage of PHP directory traversal function opendir. Share it with everyone for your reference. The specific analysis is as follows:

The function of the opendir() function is to open a directory handle. If the function runs successfully, it will return a set of directory streams (a set of directory strings). If it fails, it will return an error [error]. You can do this at the end of the function. Prepend "@" to hide errors.

syntax syntax: opendir(directory,context) parameter

Parameter: description

Description: directory required. specifies the directory to stream  

Required parameters, specify the directory object, optional parameters, specify the context of the directory object that needs to be processed. This context includes a set of options, which can change the display mode of the text stream. The example code is as follows:

Copy code The code is as follows:
$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"."
";
}
closedir($dh);
}
}
?>

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/915439.htmlTechArticlePHP directory traversal function opendir usage example, phpopendir This article describes the usage of php directory traversal function opendir. Share it with everyone for your reference. The specific analysis is as follows: opendir() function...
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