Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] rozmiar zawartosci katalogu
Forum PHP.pl > Forum > Przedszkole
hhg
czy zna ktos z Was skrypt/sposob na sprawdzenie jaki jest rozmiar (ile zajmuje w mb) zawratosci katalogu? moze zawierac podkatalogi..

z gory dzieki za odp
Daimos
pierwszy wynik z google:
  1. <?php
  2. function getDirectorySize($path)
  3. {
  4. $totalsize = 0;
  5. $totalcount = 0;
  6. $dircount = 0;
  7. if ($handle = opendir ($path))
  8. {
  9. while (false !== ($file = readdir($handle)))
  10. {
  11. $nextpath = $path . '/' . $file;
  12. if ($file != '.' && $file != '..' && !is_link ($nextpath))
  13. {
  14. if (is_dir ($nextpath))
  15. {
  16. $dircount++;
  17. $result = getDirectorySize($nextpath);
  18. $totalsize += $result['size'];
  19. $totalcount += $result['count'];
  20. $dircount += $result['dircount'];
  21. }
  22. elseif (is_file ($nextpath))
  23. {
  24. $totalsize += filesize ($nextpath);
  25. $totalcount++;
  26. }
  27. }
  28. }
  29. }
  30. closedir ($handle);
  31. $total['size'] = $totalsize;
  32. $total['count'] = $totalcount;
  33. $total['dircount'] = $dircount;
  34. return $total;
  35. }
  36.  
  37. function sizeFormat($size)
  38. {
  39. if($size<1024)
  40. {
  41. return $size." bytes";
  42. }
  43. else if($size<(1024*1024))
  44. {
  45. $size=round($size/1024,1);
  46. return $size." KB";
  47. }
  48. else if($size<(1024*1024*1024))
  49. {
  50. $size=round($size/(1024*1024),1);
  51. return $size." MB";
  52. }
  53. else
  54. {
  55. $size=round($size/(1024*1024*1024),1);
  56. return $size." GB";
  57. }
  58.  
  59. }
  60.  
  61.  
  62. $path="/httpd/html/pradeep/";
  63. $ar=getDirectorySize($path);
  64.  
  65. echo "<h4>Details for the path : $path</h4>";
  66. echo "Total size : ".sizeFormat($ar['size'])."<br>";
  67. echo "No. of files : ".$ar['count']."<br>";
  68. echo "No. of directories : ".$ar['dircount']."<br>";
  69. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.