• Resolved Ellsinore

    (@ellsinore)


    Hi, David!

    For my media library (http://cousin-collector.com/blog/?page_id=690), I’ve been able to use either IPTC metadata or the WP media item information for my listings. The one thing that’s evading me is the file size. I see that WP lists that information, but I don’t know the code to access it, so it has to get it from the photo or PDF itself each time the page is loaded.

    For instance, the first PDF in the list has this line:

    Uploaded: 12 March 2017 Modified: 12 March 2017 (293.0 KB)

    I’m using:
    {+file_size,kbmb( 1024 , ' KB', ' MB', 1 )+}

    But IIRC it would be more efficient to access the WP field for this? Such as with the Description field?

    {+description+}

    Thanks!

    Kris

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for an interesting question. You wrote “I see that WP lists that information …” I assume you mean that the file size appears, for example, in the “Save” metabox at the upper-right part of the Media/Edit Media admin screen; is that right?

    As far as I know, WordPress does not store the file size anywhere in the database, as it does for fields like Description. I did a quick search of the WordPress code and found many places where the PHP filesize() function is used to find the file size. This is the same function MLA uses to populate the {+file_size+} data source.

    You could map this value to a custom field, but I don’t think that is any more efficient than accessing the value directly when you need it. If filesize() is good enough for WordPress, it should suffice for your application as well.

    I am marking this topic resolved, but please update it if you have further questions about finding the file size for your application.

    Thread Starter Ellsinore

    (@ellsinore)

    Hi, David!

    Just for archival purposes, yes, this is where I’m finding the size information in the WP media admin screen:

    Screenshot

    If filesize() is good enough for WP, it’s good enough for me.

    Thanks! 🙂

    Kris

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Code for WP “file size” Field’ is closed to new replies.