Example 1 — Show Free Space with the Alias
Use diskfreespace() to read the free bytes and show them in gigabytes. Your number will be different.
<?php
$bytes = diskfreespace(__DIR__);
$gb = $bytes / 1024 / 1024 / 1024;
echo "Free space: ", number_format($gb, 2), " GB", PHP_EOL; How It Works
- diskfreespace(__DIR__) returns the free bytes on the current disk.
- We divide by 1024 three times to get gigabytes.
- number_format() rounds the value to two decimals.
- The text is printed with a label.

