Home  >  Article  >  Backend Development  >  How to read directories and files recursively in php, _PHP tutorial

How to read directories and files recursively in php, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:28719browse

How to read directories and files recursively in php,

The example in this article describes the method of reading directories and files recursively in PHP. Share it with everyone for your reference. The details are as follows:

This example analyzes the method of reading directories and files recursively in PHP. The code contains more detailed comments, as shown below:

<&#63;php
function showdir($path){
 $dh = opendir($path);//打开目录
 while(($d = readdir($dh)) != false){
 //逐个文件读取,添加!=false条件,是为避免有文件或目录的名称为0
 if($d=='.' || $d == '..'){//判断是否为.或..,默认都会有
 continue;
 }
 echo $d."<br />";
 if(is_dir($path.'/'.$d)){//如果为目录
 showdir($path.'/'.$d);//继续读取该目录下的目录或文件
 }
 }
}

$path = './';//当前目录
showdir($path);
&#63;>

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/950893.htmlTechArticleHow to read directories and files recursively in php. This article describes how to read directories and files recursively in php. method. Share it with everyone for your reference. The details are as follows: Here is an example analysis p...
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