How can PHP be used to determine the server's storage space?

To determine the server's storage space using PHP, you can use the disk_total_space() and disk_free_space() functions. These functions return the total and available disk space in bytes, respectively. By subtracting the available space from the total space, you can calculate the used storage space.

$total_space = disk_total_space("/");
$free_space = disk_free_space("/");
$used_space = $total_space - $free_space;

echo "Total Space: " . formatBytes($total_space) . "<br>";
echo "Free Space: " . formatBytes($free_space) . "<br>";
echo "Used Space: " . formatBytes($used_space);

function formatBytes($bytes, $precision = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB');

    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);

    $bytes /= (1 << (10 * $pow));

    return round($bytes, $precision) . ' ' . $units[$pow];
}