Library contents

PHP disk_total_space

Inspect the capacity of the volume containing a directory.

A simple example

disk_total_space

  1. Start with Example volume with 10 units total and 4 available
  2. Do this Compare a 3-unit request with available space
  3. Result It fits
The available-space reading is a snapshot. Three is below four in this illustration.

Syntax

PHP syntax
disk_total_space($base)
Run these examples in PHP

Save one example at a time as lesson.php. Use PHP 8.2 or later.

php lesson.php

Check room for a class recording

A teacher wants to record a lesson on a chosen local volume. Query capacity for the directory that will hold the recording so a large system drive cannot mask a nearly full destination.

Resultmeasured
lesson.php
<?php
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(12));
if (!mkdir($base, 0700)) throw new RuntimeException("Cannot create workspace");
try {
    $total = disk_total_space($base);
    if ($total !== false && $total > 0) echo "measured", PHP_EOL;
} finally {
    rmdir($base);
}
Output
measured

The queried volume reports a positive total capacity.

Advertisements

Prepare a gallery label

A curator stores a short UTF-8 caption beside an exhibit. On a drive with room to spare, compare its available byte count with the size of one extra copy. Can this copy fit?

GivenFile contents “clay”
Worked resultFits

Prepare a studio handover

A stage manager saves a two-word instruction for the next shift. On a drive with room to spare, compare its available byte count with the size of one extra copy. Can this copy fit?

GivenFile contents “ring bell”
Worked resultFits

What to watch for

Space figures can change while the application runs and may be limited by account quotas.

Documentation for disk_total_space