From a5ac997098b76f69a3be06fa0b5688f1cd7f4ed9 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Thu, 2 Jul 2015 19:51:14 +0100 Subject: [PATCH] DiskSpace --- DiskStatus.class.php | 73 +++++++++++++++++++++++ space.php | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 DiskStatus.class.php create mode 100644 space.php 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:\ (of )
+
usedSpace() ?>% 
+
D:\ (of )
+
usedSpace() ?>% 
+
E:\ (of )
+
usedSpace() ?>% 
+
F:\ (of )
+
usedSpace() ?>% 
+
G:\ (of )
+
usedSpace() ?>% 
+
H:\ (of )
+
usedSpace() ?>% 
+
J:\ (of )
+
usedSpace() ?>% 
+
+ + + \ No newline at end of file