Rumah >pembangunan bahagian belakang >tutorial php > 如何查看目录上的全部文件(包括子目录)?跪求大神帮忙
怎么查看目录下的全部文件(包括子目录)?跪求大神帮忙。
现有代码如下:
<?php<br /> $handle=opendir("./");<br /> while(false!==($file=readdir($handle))){<br /> if ($file != "." && $file != ".."){<br /> echo "$file<br>";<br /> }<br /> }<br /> closedir($handle);<br /> <br /> ?>
<br /> public function listDir($path, $size=false, $toCsv=false)<br /> {<br /> if (false !== $toCsv) $newCsv = new SplFileObject($toCsv, 'wb');<br /> <br /> $items = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));<br /> $arr = array();<br /> while (list($itemName, $item) = each($items))<br /> //foreach($dir as $itemName => $item)<br /> {<br /> $fileInfo = array();<br /> $fileInfo['fullpath'] = (string)$itemName;<br /> if ($size) $fileInfo['size'] = (string)$item->getSize();<br /> <br /> if (false !== $toCsv) $newCsv->fputcsv($fileInfo);<br /> $arr[] = $fileInfo;<br /> }<br /> return $arr;<br /> }<br />
function show($dir)<br> { <br> echo "<b>{$dir}</b><br>";<br> $dir = realpath($dir) .'/*';<br> foreach(glob($dir, GLOB_MARK) as $f){<br> if( substr($f, -5) === '.html' ){<br> $f = "<span>{$f}</span>";<br> }<br> echo $f ."<br>".PHP_EOL;<br> if(is_dir($f)){<br> show($f); <div class="clear"> </div>