The disk_total_space Function

The disk_total_space function returns the total disk space for the specified disk or partition. The parameter is passed as a path to the disk in the form of a string. The function returns the number of bytes as a float type number.

Syntax

phpdisk_total_space(directory);

Example

Get the total size of the C drive:

php<?php
  $res = disk_total_space('C:');
  echo $res;
?>

Code execution result (example):

php256060440576

Example

Convert bytes to gigabytes for easier reading:

php<?php
  $bytes = disk_total_space('C:');
  $gb = $bytes / 1024 / 1024 / 1024;
  echo round($gb, 2) . ' GB';
?>

Code execution result (example):

php'238.47 GB'

Example

Check available space on another drive:

php<?php
  $res = disk_total_space('D:');
  var_dump($res);
?>

Code execution result (example):

phpfloat(512110881024)

See Also

  • the disk_free_space function,
    which returns free space
  • the filesize function,
    which returns file size
  • the realpath function,
    which returns the absolute path