DiskInfo.php 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class DiskInfo {
  3. private $_disk;
  4. private static $Postfix=["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  5. public function __construct($disk) {
  6. $this->_disk=$disk;
  7. }
  8. public function __get($name) {
  9. return $this->$name();
  10. }
  11. private function HumanSize($bytes) {
  12. $index=0;
  13. while ($bytes>=1024) {
  14. $bytes/=1024;
  15. $index++;
  16. }
  17. return round($bytes, 2).self::$Postfix[$index];
  18. }
  19. private function FreeSpace() {
  20. return $this->HumanSize(disk_free_space($this->_disk));
  21. }
  22. private function TotalSpace() {
  23. return $this->HumanSize(disk_total_space($this->_disk));
  24. }
  25. private function PercentageUsed(){
  26. $free=disk_free_space($this->_disk);
  27. $total=disk_total_space($this->_disk);
  28. $remaining=($total-$free)/$total;
  29. return round($remaining*100,2);
  30. }
  31. private function Disk(){
  32. return $this->_disk;
  33. }
  34. }