Home > Backend Development > PHP Tutorial > PHP implementation to calculate the size of a folder

PHP implementation to calculate the size of a folder

WBOY
Release: 2016-07-25 08:45:26
Original
999 people have browsed it
  1. function dirSize($directoty){
  2. $dir_size=0;
  3. if($dir_handle=@opendir($directoty))
  4. {
  5. while($filename=readdir($dir_handle)){
  6. $subFile=$directoty.DIRECTORY_SEPARATOR.$filename;
  7. if($filename=='.'||$filename=='..'){
  8. continue;
  9. }elseif (is_dir($subFile))
  10. {
  11. $dir_size+=dirSize($subFile);
  12. }elseif (is_file($subFile)){
  13. $dir_size+=filesize($subFile);
  14. }
  15. }
  16. closedir($dir_handle);
  17. }
  18. return ($dir_size);
  19. }
  20. $dir_size=dirSize("xym");
  21. echo round($dir_size/pow(1024,1),2)."KB";
复制代码

PHP


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template