Make WordPress Core


Ignore:
Timestamp:
03/10/2022 01:08:19 PM (2 years ago)
Author:
spacedmonkey
Message:

Media: Store attachment’s file size in metadata.

Store the file size of all newly uploaded attachments, as part of the metadata stored in post meta. Storing file size means, developers will not have to resort to doing filesize function calls, that can be time consuming on assets on offloaded to services like Amazon’s S3.

This change also introduces a new helper function called, wp_filesize. This is a wrapper around the filesize php function, that adds some helpful filters and ensures the return value is an integer.

Props Cybr, Spacedmonkey, SergeyBiryukov, johnwatkins0, swissspidy, desrosj, joemcgill, azaozz, antpb, adamsilverstein, uday17035.
Fixes #49412.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r52797 r52837  
    40474047        $bytes = $meta['filesize'];
    40484048    } elseif ( file_exists( $attached_file ) ) {
    4049         $bytes = filesize( $attached_file );
     4049        $bytes = wp_filesize( $attached_file );
    40504050    } else {
    40514051        $bytes = '';
Note: See TracChangeset for help on using the changeset viewer.