Home >php教程 >PHP源码 >计算一个文件夹的大小

计算一个文件夹的大小

PHP中文网
PHP中文网Original
2016-05-25 17:08:551246browse

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==&#39;.&#39;||$filename==&#39;..&#39;){
    				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";
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:禁用 MediaWiki 的登录和注销Next article:php年终抽奖