Last active
July 8, 2019 16:05
-
-
Save greg-randall/537324160c90231d818ed030699acdda to your computer and use it in GitHub Desktop.
Prints out the free space and the total space on a web server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$folder = "."; | |
$free = disk_free_space($folder); | |
$total = disk_total_space($folder); | |
echo '<strong>Free Space:</strong> ' . formatBytes($free) . ' (' . round( ($free / $total) * 100 , 1) . '%)<br>'; | |
echo '<strong>Total Space:</strong> ' . formatBytes($total); | |
function formatBytes($bytes, $precision = 2) { //https://stackoverflow.com/posts/2510459/revisions | |
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); | |
$bytes = max($bytes, 0); | |
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); | |
$pow = min($pow, count($units) - 1); | |
$bytes /= pow(1024, $pow); | |
return round($bytes, $precision) . ' ' . $units[$pow]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment