php计算一个文件大小的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php计算一个文件大小的方法。分享给大家供大家参考。具体如下:

<?php
  function dirSize($directoty){
    $dir_size=0;
    if($dir_handle=@opendir($directoty))
    {
      while($filename=readdir($dir_handle)){
        $subFile=$directoty.DIRECTORY_SEPARATOR.$filename;
        if($filename=='.'||$filename=='..'){
          continue;
        }elseif (is_dir($subFile))
        {
          $dir_size+=dirSize($subFile);
        }elseif (is_file($subFile)){
          $dir_size+=filesize($subFile);
        }
      }
      closedir($dir_handle);
    }
    return ($dir_size);
  }
  $dir_size=dirSize("xym");
  echo round($dir_size/pow(1024,1),2)."KB";
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

file_get_contents获取不到网页内容的解决方法

复制代码 代码如下: <?php $url = "http://jb51.net/index.html"; $ch = curl_init(); $timeout = 5...

ASP和PHP实现生成网站快捷方式并下载到桌面的方法

在网站上设置“加入收藏、设为首页”等按钮是一般网站都会干的事儿,但是有的网站还有“放到桌面”这样的功能设置。下面即生成快捷方式并下载到桌面的php实现代码,摘录修改于网络,仅作参考 ph...

PHP函数实现从一个文本字符串中提取关键字的方法

本文实例讲述了PHP函数实现从一个文本字符串中提取关键字的方法。分享给大家供大家参考。具体分析如下: 这是一个函数定位接收一个字符串作为参数(连同其他配置可选参数),并且定位该字符串中的...

真正的ZIP文件操作类(php)

<? /******************** 作者未知 整理: Longbill ( www.longbill.cn ; lo...

PhpDocumentor 2安装以及生成API文档的方法

官网地址:http://www.phpdoc.org/项目地址:https://github.com/phpDocumentor/phpDocumentor2 phpDocumentor...