Example 1 — Show Free Disk Space in GB
Read the free bytes and convert them to gigabytes. Your number will be different.
<?php
$bytes = disk_free_space(__DIR__);
$gb = $bytes / 1024 / 1024 / 1024;
echo "Free space: ", number_format($gb, 2), " GB", PHP_EOL; How It Works
- disk_free_space(__DIR__) returns the free bytes on the current disk.
- We divide by 1024 three times to convert bytes to gigabytes.
- number_format() rounds the number to two decimal places.
- The result is printed with a label.

