Oihana PHP

getFileSize.php

Table of Contents

Functions

getFileSize()  : int
Returns the size of a file, in bytes.

Functions

getFileSize()

Returns the size of a file, in bytes.

getFileSize(string $file) : int

A thin, exception-throwing wrapper around filesize(): the file is first validated with assertFile() (must exist and be readable), so a missing file raises a typed FileException rather than a warning + false.

Parameters
$file : string

Path to the file to measure.

Tags
throws
FileException

If the file is missing, unreadable, or its size cannot be read.

author

Marc Alcaraz (ekameleon)

since
1.2.0
see
formatFileSize()

To render the returned byte count as a human-readable string.

example
use function oihana\files\getFileSize;

$bytes = getFileSize( '/data/report.pdf' ) ; // e.g. 1240518
Return values
int

The file size in bytes.

On this page

Search results