手机
当前位置:查字典教程网 >编程开发 >php教程 >PHP遍历目录并返回统计目录大小
PHP遍历目录并返回统计目录大小
摘要:复制代码代码如下:

复制代码 代码如下:

<?php

$dirname = "test1";

//mkdir($dirname);

//遍历一层目录

function listdir($dirname) {

$ds = opendir($dirname);

while($file = readdir($ds)) {

$path = $dirname.'/'.$file;

if(is_dir($file)) {

echo "DIR:".$file."<br>";

if($file != "." && $file != "..") {

listdir($file);

}

}

else {

echo "FILE:".$file . "<br>";

}

}

}

function totdir($dirname) { //对listdir稍加修改

static $tot = 0;

$ds = opendir($dirname);

while($file = readdir($ds)) {

$path = $dirname.'/'.$file;

if(is_dir($file)) {

//echo "DIR:".$file."<br>";

if($file != "." && $file != "..") {

$tot += totdir($file);

}

}

else {

//echo "FILE:".$file . "<br>";

$tot += filesize($path);

}

}

//返回总计

return $tot;

}

listdir($dirname);

echo totdir($dirname)." bytes";

?>

【PHP遍历目录并返回统计目录大小】相关文章:

PHP个人网站架设连环讲(一)

PHP实现的增强性mhash函数

聊天室php&mysql(四)

PHP数据库开发知多少

PHP时间和日期函数详解

PHP网络操作函数汇总

用PHP实现小型站点广告管理

PHP中创建并处理图象

php使用GD实现颜色渐变实例

用PHP实现小型站点广告管理(修正版)

精品推荐
分类导航