What is the disk_total_space function in PHP?

In PHP, we can use the disk_total_space function to get the total space available.

This function will not work on remote files.

Syntax

disk_total_space(string $directory): float|false

Parameters

The function needs a directory or a partition as a mandatory parameter.

Return value

The function will return a floating number that represents the total space of the specified directory. Otherwise, it will return false.

Code

In this example, we will return the size of root directory.

<?php
$ds = disk_total_space("/home");
echo $ds;
?>

The size returned is in bytes.

Free Resources