PHP calculates the size of a folder

WBOY
Release: 2016-07-25 09:01:24
Original
870 people have browsed it
PHP calculates the size of a folderhttp://blog.1dnet.net/?post=839
  1. //http://blog.1dnet.net
  2. function dirSize($directoty){
  3. $dir_size=0;
  4. if($dir_handle=@opendir($directoty))
  5. {
  6. while($filename=readdir($dir_handle)){
  7. $subFile=$directoty.DIRECTORY_SEPARATOR.$filename;
  8. if($filename=='.'||$filename=='..'){
  9. continue;
  10. }elseif (is_dir($subFile))
  11. {
  12. $dir_size+=dirSize($subFile);
  13. }elseif (is_file($subFile)){
  14. $dir_size+=filesize($subFile);
  15. }
  16. }
  17. closedir($dir_handle);
  18. }
  19. return ($dir_size);
  20. }
  21. $dir_size=dirSize("xym");
  22. echo round($dir_size/pow(1024,1),2)."KB";
  23. ?>
复制代码


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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!