wp_filesize() WordPress Function
The wp_filesize() function is used to display the filesize of a given file in human-readable format. This function is especially useful for displaying the filesize of images, as it can take into account the file's compression level.
wp_filesize( string $path ) #
Wrapper for PHP filesize with filters and casting the result as an integer.
Parameters
- $path
(string)(Required)Path to the file.
Return
(int) The size of the file in bytes, or 0 in the event of an error.
Source
File: wp-includes/functions.php
function wp_filesize( $path ) {
/**
* Filters the result of wp_filesize before the PHP function is run.
*
* @since 6.0.0
*
* @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
* @param string $path Path to the file.
*/
$size = apply_filters( 'pre_wp_filesize', null, $path );
if ( is_int( $size ) ) {
return $size;
}
$size = file_exists( $path ) ? (int) filesize( $path ) : 0;
/**
* Filters the size of the file.
*
* @since 6.0.0
*
* @param int $size The result of PHP filesize on the file.
* @param string $path Path to the file.
*/
return (int) apply_filters( 'wp_filesize', $size, $path );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |