Home > 类库下载 > PHP类库 > body text

Usage examples of opendir function in php

高洛峰
Release: 2016-10-09 11:24:11
Original
1175 people have browsed it

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. It has certain reference value. Friends in need can refer to it

Examples in this article Analyzed the usage of opendir function in php. 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 take a look at opendir List all file instances in the directory, 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 results:
File name: a
File name: b
File name: www.manongjc.com

Tips and comments:

Comments: From PHP 5.0. Starting from 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.

Related reading:

http://www.manongjc.com/article/1495.html

http://www.manongjc.com/article/1496.html


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template