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

计算一个文件夹的大小

PHP中文网
Release: 2016-05-25 17:08:55
Original
1282 people have browsed it

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";
?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template