diff --git a/DiskStatus.class.php b/DiskStatus.class.php new file mode 100644 index 0000000..b988175 --- /dev/null +++ b/DiskStatus.class.php @@ -0,0 +1,73 @@ +diskPath = $diskPath; + } + + + public function totalSpace($rawOutput = false) { + $diskTotalSpace = @disk_total_space($this->diskPath); + + if ($diskTotalSpace === FALSE) { + throw new Exception('totalSpace(): Invalid disk path.'); + } + + return $rawOutput ? $diskTotalSpace : $this->addUnits($diskTotalSpace); + } + + + public function freeSpace($rawOutput = false) { + $diskFreeSpace = @disk_free_space($this->diskPath); + + if ($diskFreeSpace === FALSE) { + throw new Exception('freeSpace(): Invalid disk path.'); + } + + return $rawOutput ? $diskFreeSpace : $this->addUnits($diskFreeSpace); + } + + + public function usedSpace($precision = 1) { + try { + return round((100 - ($this->freeSpace(self::RAW_OUTPUT) / $this->totalSpace(self::RAW_OUTPUT)) * 100), $precision); + } catch (Exception $e) { + throw $e; + } + } + + + public function getDiskPath() { + return $this->diskPath; + } + + + private function addUnits($bytes) { + $units = array( 'B', 'KB', 'MB', 'GB', 'TB' ); + + for($i = 0; $bytes >= 1024 && $i < count($units) - 1; $i++ ) { + $bytes /= 1024; + } + + return round($bytes, 1).' '.$units[$i]; + } + +} + +?> + \ No newline at end of file diff --git a/space.php b/space.php new file mode 100644 index 0000000..aa5b344 --- /dev/null +++ b/space.php @@ -0,0 +1,139 @@ + + +
+ + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus1 = new DiskStatus('d:'); + + $freeSpace1 = $diskStatus1->freeSpace(); + $totalSpace1 = $diskStatus1->totalSpace(); + $barWidth1 = ($diskStatus1->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} +try { + $diskStatus2 = new DiskStatus('e:'); + + $freeSpace2 = $diskStatus2->freeSpace(); + $totalSpace2 = $diskStatus2->totalSpace(); + $barWidth2 = ($diskStatus2->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus3 = new DiskStatus('f:'); + + $freeSpace3 = $diskStatus3->freeSpace(); + $totalSpace3 = $diskStatus3->totalSpace(); + $barWidth3 = ($diskStatus3->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus4 = new DiskStatus('g:'); + + $freeSpace4 = $diskStatus4->freeSpace(); + $totalSpace4 = $diskStatus4->totalSpace(); + $barWidth4 = ($diskStatus4->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus5 = new DiskStatus('h:'); + + $freeSpace5 = $diskStatus5->freeSpace(); + $totalSpace5 = $diskStatus5->totalSpace(); + $barWidth5 = ($diskStatus5->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus6 = new DiskStatus('j:'); + + $freeSpace6 = $diskStatus6->freeSpace(); + $totalSpace6 = $diskStatus6->totalSpace(); + $barWidth6 = ($diskStatus6->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + +Disk Space |
C:\= $freeSpaceC ?> (of = $totalSpaceC ?>) |
+ = $diskStatusC->usedSpace() ?>%
+ |
D:\= $freeSpace1 ?> (of = $totalSpace1 ?>) |
+ = $diskStatus1->usedSpace() ?>%
+ |
E:\= $freeSpace2 ?> (of = $totalSpace2 ?>) |
+ = $diskStatus2->usedSpace() ?>%
+ |
F:\= $freeSpace3 ?> (of = $totalSpace3 ?>) |
+ = $diskStatus3->usedSpace() ?>%
+ |
G:\= $freeSpace4 ?> (of = $totalSpace4 ?>) |
+ = $diskStatus4->usedSpace() ?>%
+ |
H:\= $freeSpace5 ?> (of = $totalSpace5 ?>) |
+ = $diskStatus5->usedSpace() ?>%
+ |
J:\= $freeSpace6 ?> (of = $totalSpace6 ?>) |
+ = $diskStatus6->usedSpace() ?>%
+ |