In PHP, disk_total_space() returns the total size in bytes of the disk or partition that contains a folder. It tells you how big the disk is, not how much is used.
Use it together with disk_free_space() to show how full a disk is. The result is a float, and it is false if the folder is not valid or the information cannot be read.
Syntax
Call disk_total_space() with the values you need. Start with this line.
PHP
$bytes = disk_total_space(__DIR__);
Call
What it does
disk_total_space(__DIR__)
Returns the total bytes of the disk that holds the script folder.
disk_total_space("/")
Returns the total bytes of the root partition (Linux and macOS).
disk_total_space("C:")
Returns the total bytes of the C drive (Windows).
The value is the size of the whole disk or partition, even if only part of it is available to your user. Combine it with disk_free_space() to work out the used space.
Library declarations
PHP
disk_total_space(string $directory): float|false
Parameters
Parameter
Description
directory
Required. A folder on the disk or partition you want to check.
Return Value
Return Value
Description
float
The total size of the disk or partition in bytes.
false
Returned if the folder is not valid or the information cannot be read.
PHP Examples
Example 1 — Show the Total Disk Size in GB
Read the total bytes and convert them to gigabytes. Your number will be different.