PHP递归读取一个路径下的目录及文件

2018-08-04 03:28:03
Reading:368
<?php
function getdir($path){
	$dir = opendir($path);
	while(($d = readdir($dir)) == true){ //不让.和..出现在读取出的列表里
		if($d == '.' || $d == '..'){ continue; }
		echo $d.' '; //判断如果是目录,继续读取
		if(is_dir($path.'/'.$d)){ getdir($path.'/'.$d); }
	}
}
$path = '../';
getdir($path);
?>

About

When I was young
I'd listen to the radio
Waiting for my favorite songs
When they played I'd sing along
It made me smile
Those were such happy times
And not so long ago
How I wondered where they'd gone
But they're back again
Just like a long lost friend
All the songs I loved so well