263 of 410 menu

The disk_free_space Function

The disk_free_space function returns the amount of free space in bytes on the specified disk or filesystem. The function accepts one parameter - the path to the disk to check. In Windows, you can specify either a drive letter (for example, 'C:') or a path to a directory. In Unix systems, the path to the mount point is specified.

Syntax

disk_free_space(directory);

Example

Get free space on drive C: in Windows:

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

Code execution result (example):

1073741824

Example

Get free space in the root directory of a Unix system:

<?php $res = disk_free_space('/'); echo $res; ?>

Code execution result (example):

2147483648

Example

Convert bytes to gigabytes for convenient display:

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

Code execution result (example):

'15.75 GB'

See Also

byenru