Get ACF File size and type


Is there a way for L&L to get an ACF File size (in Ko…) and type (like PDF, Word…)?

Here’s what i used to do with CCS for the file size.
Looking for a way to do that with L&L.

[array res_pdf_file debug=false]
    Size: [format decimals=0 point=, thousands=.][calc][field filesize]/1000[/calc][/format] KB

Thanks for your help

I ended up coding a custom PHP shortcode.

Hi Emmanuel,

The Attachment loop type, which is what ACF File field uses internally, now supports the fields size and type. So it should be possible to do:

<Loop acf_file=field_name>
  File: <Field url /><br>
  Type: <Field type /><br>
  Size: <Field size /><br>

The file size is formatted to be human-readable, with MB, KB, etc.

That’s great, than you @eliot!

Hi @eliot,

I’ve just tried looping through an acf_file field using your code sample above.
The url and type fields works fine but the size field returns nothing, strange…

The ACF File field is set to return an Array.

Using the latest versions:

  • WP 6.1.1
  • ACF Pro 6.0.7
  • Loops & Logic 3.1.1

I just tried with the exact same settings as you (I have the same plugin versions and my file field is set to return an array) and using the template that Eliot shared above worked for me. I uploaded a 3 MB (3,275,915 bytes) PDF to a CPT and the output was this:

File: http://my-bicycle-shop.test/wp-content/uploads/2022/03/Giant-Stance-29-2-2703.pdf
Type: application/pdf
Size: 3275915

Is there anything else going on on your site that might be causing this? Are you able to replicate it on a fresh WP installation? Let me know what you find.

Thank you for testing.

I’m not sure what prevents L&L to access the PDF size on my site.
All i think of for now, the PDF are set in an ACF File located in an Option page.

Just for the sake of testing, I tried working with an ACF file field from an options page by adding from=options to my Loop and Field tags and it worked as expected, giving me the file size. Let me know if your testing reveals anything that might be causing this issue on your particular installation.

Thanks for the additional testing @benjamin, i’ll inspect deeper on my side.