php查询指定目录下所有文件并保存到数组
<?php $dirs = array(); foreach (glob("test/*") as $d) { if (is_dir($d)) { $dirs[] = $d; } } print_r($dirs); //方法二 glob("test/*", glob_onlydir); //查找目录下所有文件 function listdir($dir) { if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ((is_dir($dir . "/" . $file)) && $file != "." && $file != "..") { echo "<b><font color='red'>文件名:</font></b>", $file, "<br><hr>"; listdir($dir . "/" . $file . "/"); } else { if ($file != "." && $file != "..") { echo $file . "<br>"; } } } closedir($dh); } } } //开始运行 listdir("e:/www.phprm.com/");
文章链接:http://www.phprm.com/code/33613.html
随便收藏,请保留本文地址!