I'm using Advanced Custom Fields to display some uploaded items on the website, but I also need to display the size of the files.

I have this code:

$filevalue = get_field('file_bestand');
$filesize = filesize( get_attached_file( $filevalue ) );
$filesize = size_format($filesize, 2);

echo $filesize;

But it's not showing me anything...

Is there anyone who can help me with this?

  • 1
    what you see on var_dump($filesize)? to get filesize, you need file path and use echo filesize("file path"); – Vishwa Apr 26 '19 at 8:55
  • @Vishwa on var_dump($filesize) I get NULL – n00bly Apr 26 '19 at 10:42
  • @Vishwa $filevalue gives the path to the file. – n00bly Apr 26 '19 at 10:44
  • I think you just answered your own question – tmdesigned Apr 26 '19 at 22:37
  • Try filesize( $filevalue ); instead of using the get_attached_file function in the middle. – tmdesigned Apr 26 '19 at 22:38

A var_dump shows that filesize is a property of the ACF file field.

echo '<pre>';
    var_dump( $file_bestand );
echo '</pre>';

to output the filesize for field file_bestand

$file_bestand = get_field('file_bestand'); 
$filesize = $file_bestand['filesize'];
$filesize = size_format($filesize, 2);
  • You probably use different names for the same variable: $file_bestand and $file. – nmr Mar 19 at 15:02
  • Thanks, have corrected vars – katiedev Mar 20 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.