folder-size.php 873 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2019 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * Simple functon to get the size of a folder
  15. * ignores . files and does not really work well with large files
  16. *
  17. * @param string $folder Absolute path to folder
  18. */
  19. function folderSize($folder) {
  20. $ret = 0;
  21. if(file_exists($folder) && is_readable($folder)) {
  22. foreach (glob(rtrim($folder, '/') . '/*', GLOB_NOSORT) as $each) {
  23. $ret += is_file($each) ? filesize($each) : folderSize($each);
  24. }
  25. }
  26. return $ret;
  27. }