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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources