Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] rozmiar zawartosci katalogu
hhg
post
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
Daimos
post
Post #2





Grupa: Zarejestrowani
Postów: 1 319
Pomógł: 118
Dołączył: 26.11.2003
Skąd: Lublin

Ostrzeżenie: (0%)
-----


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. ?>


--------------------
scriptun.com. Startup z poradnikami do gier ttp.zone i ttpzone.pl
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 06:31