[wp-trac] [WordPress Trac] #49412: Store filesize media metadata
WordPress Trac
noreply at wordpress.org
Tue Feb 18 14:33:28 UTC 2020
#49412: Store filesize media metadata
-----------------------------+-----------------------------
Reporter: Cybr | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Future Release
Component: Media | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: performance
-----------------------------+-----------------------------
Comment (by johnwatkins0):
Attaching a diff that adds "filesize" to the metadata for all attachments.
For images the field is at the top level as well as in all of the sizes in
the `sizes` array -- e.g.:
{{{
Array
(
[width] => 426
[height] => 640
[file] => 2020/02/2004-07-22-DSC_0007.jpg
[filesize] => 87348
[sizes] => Array
(
[medium] => Array
(
[file] => 2004-07-22-DSC_0007-200x300.jpg
[filesize] => 26505
[width] => 200
[height] => 300
[mime-type] => image/jpeg
)
[thumbnail] => Array
(
[file] => 2004-07-22-DSC_0007-150x150.jpg
[filesize] => 19138
[width] => 150
[height] => 150
[mime-type] => image/jpeg
)
)
[image_meta] => Array
(
... etc.
)
)
}}}
For media types such as PDF, `_wp_attachment_metadata` will be created as
needed -- e.g.:
{{{
Array
(
[_wp_attached_file] => Array
(
[0] => 2020/02/2019-Starbucks-For-Life-Data-Surfacing-
Specification.pptx
)
[_wp_attachment_metadata] => Array
(
[0] => a:1:{s:8:"filesize";i:8419858;}
)
[_edit_lock] => Array
(
[0] => 1582035593:1
)
)
}}}
Video and audio files will still have their filesize read by `getID3()` if
possible, but there is a fallback if for whatever reason `getID3()`
doesn't provide the filesize.
== Question
I think the meta key should be carefully considered. I'm using `filesize`
because it matches the PHP function and the convention I've seen in
plugins and themes that store file size in meta. There's no reason it has
to be this, though. If there's a more semantic key -- or perhaps one that
is sure to be unique and not conflict with plugins that may hook into
attachment metadata -- then it could easily be changed. Any thoughts?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49412#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list