Home › Forums › General Issues › get filesize? › Reply To: get filesize?
With this you get the extension, too:
get it:
$path_info = pathinfo( get_attached_file( $attachment_id ) );
show it:
echo $path_info['extension']
full example with a repeater field (to show some downloads):
<?php
// Downloads repeater field
if (get_row_layout() == 'download_list'): ?>
<?php if(get_sub_field('download')) { ?>
<ul class="unstyled downloads">
<?php while(has_sub_field('download')) {
$attachment_id = get_sub_field('singledl');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
$path_info = pathinfo( get_attached_file( $attachment_id ) );
?>
<li class="table">
<a href="<?php echo $url; ?>" class="download table-row break">
<span class="icon-download2 iconF icon-20 icon-fl" aria-hidden="true"></span>
<?php echo '<span class="filetitle table-cell">' . $title . ' (' . $path_info['extension'] . ')</span>' . '<span class="filesize table-cell">' . $filesize . '</span>' ?>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.