From 2fa74a076325c18564876279a71ee5ea2c8cc59e Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 18 Sep 2012 04:06:31 +0000 Subject: [PATCH] add recursive dir function --- application/models/mydir.php | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/application/models/mydir.php b/application/models/mydir.php index 06f0607b..d61a0cf1 100755 --- a/application/models/mydir.php +++ b/application/models/mydir.php @@ -33,5 +33,43 @@ class mydir{ function getLast() { return $this->list[count($this->list)-1]; + } + + function recursive($dir) + { + $files = array(); + if ($handle = opendir($dir)) + { + while (false !== ($file = readdir($handle))) + { + if ($file != "." && $file != "..") + { + if(is_dir($dir.'/'.$file)) + { + $dir2 = $dir.'/'.$file; + $files[]=$dir2; + $files[] = $this->recursive($dir2); + } else { + $files[] = $dir.'/'.$file; + } + } + } + closedir($handle); + } + return $this->array_flat($files); + } + + function array_flat($array) + { + foreach($array as $a) + { + if(is_array($a)) + { + $tmp = array_merge($tmp, array_flat($a)); + }else { + $tmp[] = $a; + } + } + return $tmp; } } \ No newline at end of file