Gets the attachment’s file size in bytes.
Parameters
$attachment_idintrequired- Attachment ID.
Source
protected function get_attachment_filesize( int $attachment_id ): ?int {
$meta = wp_get_attachment_metadata( $attachment_id );
if ( isset( $meta['filesize'] ) ) {
return $meta['filesize'];
}
$original_path = wp_get_original_image_path( $attachment_id );
$attached_file = $original_path ? $original_path : get_attached_file( $attachment_id );
if ( is_string( $attached_file ) && is_readable( $attached_file ) ) {
return wp_filesize( $attached_file );
}
return null;
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.