|
|
|
Speicherplatz ausgeben
Zurück zur Übersicht Ermittelt den freien Speicherplatz.
Ich weiß nicht ob das einer braucht!
Das hier ist ein script mitdem man den Speicherplatz in GB und % ausgeben kann:
| PHP |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
|
<?php
function getByte($bytes) {
$symbol = "Bytes";
if ($bytes > 1024) {
$symbol = "KiB";
$bytes /= 1024;
}
if ($bytes > 1024) {
$symbol = "MiB";
$bytes /= 1024;
}
if ($bytes > 1024) {
$symbol = "GiB";
$bytes /= 1024;
}
$bytes = round($bytes, 2);
return $bytes.$symbol;
}
function getFreespace($path) {
if (preg_match("#^(https?|ftps?)://#si", $path)) {
return false;
}
$freeBytes = disk_free_space($path);
$totalBytes = disk_total_space($path);
$usedBytes = $totalBytes - $freeBytes;
$percentFree = 100 / $totalBytes * $freeBytes;
$percentUsed = 100 / $totalBytes * $usedBytes;
echo "Speichertotal: ".getByte($totalBytes)."<br />";
echo "Belegter Speicher: ".getByte($usedBytes);
printf(" (%01.2f%%)", $percentUsed);
echo "<br />";
echo "Freier Speicher: ".getByte($freeBytes);
printf(" (%01.2f%%)", $percentFree);
}
//Usage
getFreespace(".");
?>
|
|
Viel Spaß damit! ;)
Kommentare
Zurück zur Übersicht
Autor Wernch
|
|
|
|