filesize()

filesize() — Gets file size.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

filesize(string $filename): int|false

Parameters

ParameterTypeWhat it takes
$filenamestringPath to the file.

Return value

Returns the size of the file in bytes, or false (and generates an error of level E_WARNING) in case of an error. Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB. Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.

Example

A runnable snippet:

// outputs e.g. somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes';

See also

file_exists()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page filesize() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.