Home > Backend Development > PHP Tutorial > Summary of PHP directory traversal method_PHP tutorial

Summary of PHP directory traversal method_PHP tutorial

WBOY
Release: 2016-07-13 10:04:18
Original
941 people have browsed it

Summary of PHP directory traversal method

This article mainly introduces the PHP directory traversal method. The example summarizes two commonly used implementation techniques, which has certain reference value. Friends in need You can refer to the following

The example in this article summarizes the PHP directory traversal method. Share it with everyone for your reference. The details are as follows:

1. Method 1

?

1

2

3

4

5

6

7

8

9

10

11

12

function myscandir($pathname){

foreach( glob($pathname) as $filename ){

if(is_dir($filename)){

myscandir($filename.'/*');

}else{

echo $filename.'
';

}

}

}

myscandir('D:/wamp/www/exe1/*');

?>

1 2

3

4

5

6

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

function myscandir($path){

$mydir=dir($path);

while($file=$mydir->read()){

$p=$path.'/'.$file;

if(($file!=".") AND ($file!="..")){

echo $p.'
';

}

if((is_dir($p)) AND ($file!=".") AND ($file!="..")){

myscandir($p);

}

}

}

myscandir(dirname(dirname(__FILE__)));

?>

7 8

9 10

11

function myscandir($pathname){ foreach( glob($pathname) as $filename ){ if(is_dir($filename)){ myscandir($filename.'/*');

}else{
echo $filename.'
'; } } } myscandir('D:/wamp/www/exe1/*'); ?>
2. Method 2 ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <🎜>function myscandir($path){<🎜> <🎜>$mydir=dir($path);<🎜> <🎜>while($file=$mydir->read()){ $p=$path.'/'.$file; if(($file!=".") AND ($file!="..")){ echo $p.'
'; } if((is_dir($p)) AND ($file!=".") AND ($file!="..")){ myscandir($p); } } } myscandir(dirname(dirname(__FILE__))); ?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/966366.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966366.htmlTechArticleSummary of PHP directory traversal method This article mainly introduces the PHP directory traversal method, and the examples summarize the two commonly used implementations The skills have certain reference value. Friends in need can refer to it...
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