Attachment metadata and filesize
-
I’ve noticed that various places in the media admin UI display an attachment’s filesize.
The procedure for getting the value seems to be something like this:
$meta = wp_get_attachment_metadata( $post->ID ); $file = get_attached_file( $post->ID ); $file_size = false; if ( isset( $meta['filesize'] ) ) $file_size = $meta['filesize']; elseif ( file_exists( $file ) ) $file_size = filesize( $file );
That’s all well and good, but in browsing through a number of WP databases, I’m yet to encounter a situation where filesize actually appears in _wp_attachment_metadata.
Is storing the filesize in _wp_attachment_metadata something that’s now deprecated? Something waiting to be implemented? Neither?
I’m interested in storing this data so that I can retrieve a list of media posts ordered by their filesize. Since _wp_attachment_metadata is a serialized array it’s not actually a great thing to try and use for sorting a post query, but regardless… can/should I try and implement something in my plugin to store ‘filesize’ here, or should that be avoided?
- The topic ‘Attachment metadata and filesize’ is closed to new replies.