Home  >  Article  >  Backend Development  >  PHP code to calculate file size

PHP code to calculate file size

WBOY
WBOYOriginal
2016-07-25 08:45:50880browse
  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";
  22. ?>
复制代码

php


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:Simple php lottery codeNext article:Simple php lottery code