Skip to content

Instantly share code, notes, and snippets.

@greg-randall
Last active July 8, 2019 16:05
Show Gist options
  • Save greg-randall/537324160c90231d818ed030699acdda to your computer and use it in GitHub Desktop.
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.
<?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