Oihana PHP

getFreeDiskSpace.php

Table of Contents

Functions

getFreeDiskSpace()  : float
Returns the number of free bytes on the filesystem hosting a directory.

Functions

getFreeDiskSpace()

Returns the number of free bytes on the filesystem hosting a directory.

getFreeDiskSpace([string $directory = '.' ]) : float

Typed wrapper around disk_free_space(): an invalid path raises a FileException instead of returning false. Useful as a pre-flight guard before extracting an archive or writing large files.

Parameters
$directory : string = '.'

A directory (or path) on the filesystem to inspect (default: '.').

Tags
throws
FileException

If the free space cannot be determined (e.g. invalid path).

author

Marc Alcaraz (ekameleon)

since
1.2.0
see
getTotalDiskSpace()
getDiskUsage()
example
use function oihana\files\getFreeDiskSpace;

if ( getFreeDiskSpace( '/var/www' ) < $estimatedSize )
{
    throw new RuntimeException( 'Not enough free disk space.' ) ;
}
Return values
float

The number of available bytes.

On this page

Search results