最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php scandir遍历显示所有文件与文件夹下的文件
时间:2011-06-06 编辑:简简单单 来源:一聚教程网
php教程 scandir遍历显示所有文件与文件夹下的文件,方法很简单我们只要利用is_dir判断再递归查找一次,这样就可以把遍历目录下所有文件了。
目录遍历
function numfilesindir ($thedir){
if (is_dir ($thedir)){
$scanarray = scandir ($thedir);
for ($i = 0; $i < count ($scanarray); $i++){
if ($scanarray[$i] != "." && $scanarray[$i] != ".."){
if (is_file ($thedir . "/" . $scanarray[$i])){
echo $scanarray[$i] . "
";
}
}
}
} else {
echo "Sorry, this directory does not exist.";
}
}
echo numfilesindir ("sample1");?>
扫描指定位置的文件
print_r(scandir("/usr/local/apache2/htdocs"));
?>
$files = scandir(".", 1);
var_dump($files);
?>
-
上一个: php最简单文件上传代码
-
下一个: php update数据更新简单实例
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24