folder-size-large.php 805 B

123456789101112131415161718192021222324252627
  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. * Get the folder size with a unix command.
  15. * Usefull when on linux only and large files
  16. *
  17. * @param string $folder Absolute path to the folder
  18. */
  19. function folderSize($folder) {
  20. $io = popen ( '/usr/bin/du -sk ' . folder, 'r' );
  21. $size = fgets ( $io, 4096);
  22. $size = substr ( $size, 0, strpos ( $size, "\t" ) );
  23. pclose ( $io );
  24. return $size;
  25. }