From 6bdd0d94ec7b194f1863f507621f89325b5d2bad Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Sun, 5 Jul 2015 07:54:49 +0100 Subject: [PATCH] fix space --- drives/DiskStatus.class.php | 73 +++++++++++++ drives/drive1.php | 92 ++++++++++++++++ drives/drive2.php | 93 ++++++++++++++++ drives/drive3.php | 93 ++++++++++++++++ drives/drive4.php | 92 ++++++++++++++++ drives/drive5.php | 92 ++++++++++++++++ drives/drive6.php | 92 ++++++++++++++++ drives/drive7.php | 92 ++++++++++++++++ space_old.php | 207 ++++++++++++++++++++++++++++++++++++ 9 files changed, 926 insertions(+) create mode 100644 drives/DiskStatus.class.php create mode 100644 drives/drive1.php create mode 100644 drives/drive2.php create mode 100644 drives/drive3.php create mode 100644 drives/drive4.php create mode 100644 drives/drive5.php create mode 100644 drives/drive6.php create mode 100644 drives/drive7.php create mode 100644 space_old.php diff --git a/drives/DiskStatus.class.php b/drives/DiskStatus.class.php new file mode 100644 index 0000000..b988175 --- /dev/null +++ b/drives/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/drives/drive1.php b/drives/drive1.php new file mode 100644 index 0000000..f4159fa --- /dev/null +++ b/drives/drive1.php @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive2.php b/drives/drive2.php new file mode 100644 index 0000000..745d747 --- /dev/null +++ b/drives/drive2.php @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive3.php b/drives/drive3.php new file mode 100644 index 0000000..521e4e3 --- /dev/null +++ b/drives/drive3.php @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive4.php b/drives/drive4.php new file mode 100644 index 0000000..593b09f --- /dev/null +++ b/drives/drive4.php @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive5.php b/drives/drive5.php new file mode 100644 index 0000000..81ad1fe --- /dev/null +++ b/drives/drive5.php @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive6.php b/drives/drive6.php new file mode 100644 index 0000000..d6ba8e6 --- /dev/null +++ b/drives/drive6.php @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/drives/drive7.php b/drives/drive7.php new file mode 100644 index 0000000..0524ec2 --- /dev/null +++ b/drives/drive7.php @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + +freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + + + catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + + + + + + + + + + +
\ (of )
+
+
usedSpace() ?>% 
+
+
+ + + + + \ No newline at end of file diff --git a/space_old.php b/space_old.php new file mode 100644 index 0000000..e0aefd8 --- /dev/null +++ b/space_old.php @@ -0,0 +1,207 @@ + + + + + + + + + + + + + + + + + + + + + "0") { + try { + $diskStatusC = new DiskStatus("$drive1"); + + $freeSpaceC = $diskStatusC->freeSpace(); + $totalSpaceC = $diskStatusC->totalSpace(); + $barWidthC = ($diskStatusC->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} +} + +try { + $diskStatus1 = new DiskStatus("$drive2"); + + $freeSpace1 = $diskStatus1->freeSpace(); + $totalSpace1 = $diskStatus1->totalSpace(); + $barWidth1 = ($diskStatus1->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} +try { + $diskStatus2 = new DiskStatus("$drive3"); + + $freeSpace2 = $diskStatus2->freeSpace(); + $totalSpace2 = $diskStatus2->totalSpace(); + $barWidth2 = ($diskStatus2->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus3 = new DiskStatus("$drive4"); + + $freeSpace3 = $diskStatus3->freeSpace(); + $totalSpace3 = $diskStatus3->totalSpace(); + $barWidth3 = ($diskStatus3->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus4 = new DiskStatus("$drive5"); + + $freeSpace4 = $diskStatus4->freeSpace(); + $totalSpace4 = $diskStatus4->totalSpace(); + $barWidth4 = ($diskStatus4->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus5 = new DiskStatus("$drive6"); + + $freeSpace5 = $diskStatus5->freeSpace(); + $totalSpace5 = $diskStatus5->totalSpace(); + $barWidth5 = ($diskStatus5->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +try { + $diskStatus6 = new DiskStatus("$drive7"); + + $freeSpace6 = $diskStatus6->freeSpace(); + $totalSpace6 = $diskStatus6->totalSpace(); + $barWidth6 = ($diskStatus6->usedSpace()/100) * 150; + +} catch (Exception $e) { + echo 'Error ('.$e->getMessage().')'; + exit(); +} + +?> + +
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Disk Space
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
\ (of )
+
+
usedSpace() ?>% 
+
+
+
+
+ + + \ No newline at end of file