Hi I have the filename and fid of the uploaded file in a media entity, how can I programatically get the size and last uploaded date in my module? This is with D8 thanks

1 Answer 1


This is the code to get the size:

 $file = File::load($tid);
 $size = $file->getSize();
  • Use like \Drupal\file\Entity\File::load($tid) or add use Drupal\file\Entity\File at top of the file
    – siddiq
    Apr 5, 2018 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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