Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304771
  • 博文数量: 111
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 707
  • 用 户 组: 普通用户
  • 注册时间: 2013-02-26 11:00
个人简介

小伙向前冲呀,小伙向前冲呀。

文章分类

全部博文(111)

文章存档

2014年(43)

2013年(68)

我的朋友

分类: PHP

2014-06-12 22:01:48

分享一个 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."
"; if($file != "." && $file != "..") { listdir($file); } } else { echo "FILE:".$file . "
"; } } } function totdir($dirname) { //对listdir稍加修改 static $tot = 0; $ds = opendir($dirname); while($file = readdir($ds)) { $path = $dirname.'/'.$file; if(is_dir($file)) { //echo "DIR:".$file."
";
if($file != "." && $file != "..") { $tot += totdir($file); } } www.jbxue.com else { //echo "FILE:".$file . "
";
$tot += filesize($path); } } //返回总计 return $tot; } listdir($dirname); echo totdir($dirname)." bytes"; ?>
阅读(1464) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~