wp_filesize()
Gets the size of the specified file.
A wrapper for PHP filesize() with filters and conversion of the result to an integer.
The function wp_filesize is useful when storing attachments on external storage (Amazon’s S3, Google cloud storage, or a general network resource like NFS). This means that the value can be filtered, which prevents the possibility of slow access to an external server.
1 time — 0.0000501 sec (very fast) | 50000 times — 0.23 sec (very fast) | PHP 7.4.25, WP 6.0
Hooks from the function
Returns
Int. The file size in bytes, or 0 in case of an error.
Usage
wp_filesize( $path );
- $path(string) (required)
- The path to the file whose size is to be obtained.
Examples
#1 Get the file size through the WP function
Example when a file exists:
$path = '/path/to/file.png'; $size = wp_filesize( $path ); var_dump( $size ); // int(60235)
When the file does not exist:
$path = '/path/to/nonexistent-file.png'; $size = wp_filesize( $path ); var_dump( $size ); // int(0)
Changelog
| Since 6.0.0 | Introduced. |