I’ve got a strange problem. I’m trying to get the file size of a file uploaded from ACF. Despite reviewing this forum thread and the filesize documentation, I’m still getting errors. The upload field returns an object and so I’m attempting something like
$attachment = get_field('pdf_version');
$attached_file = get_attached_file($attachment['id']);
// which returns /var/www/html/wp-content/uploads/year/month/file.pdf
$filesize = filesize($attached_file);
The issue is that $filesize
returns false and errors with filesize(): stat failed for {path to file}
. When I check file_exists($filename)
that returns false also. However pathinfo()
gives me the correct information. So I’m kind of at a loss.
I tried running clearstatcache()
after filesize()
, but that didn’t do anything.
One other strange thing is that when I look at the field in the CPT, the size of the uploaded file isn’t there either when I suspect it should be.