Home › Forums › General Issues › how to get filetype (extension)? › Reply To: how to get filetype (extension)?
great, thanks that works 🙂
<?php if(get_field("downloads")): ?>
<div id="downloadbox">
<h3>Files</h3>
<ul class="downloads">
<?php while(the_flexible_field("downloads")): ?>
<?php if(get_row_layout() == 'flexible_download'): // layout: Content ?>
<?php $attachment_id = get_sub_field('file');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
// part where to get the filesize
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
// part where to get the extension
$path_info = pathinfo( get_attached_file( $attachment_id ) );?>
<li class="cf dlbox">
<a href="<?php echo $url; ?>" class="cf">
<span class="dl-title"><?php echo $title; ?><small><nobr><strong>Size:</strong> <em>(<?php echo $filesize; ?>)</em></nobr></small></span>
<span class="dl-extension"><span class="dl-extension-inner"><?php echo $path_info['extension']; ?></span></span>
</a>
</li>
<?php endif; endwhile; ?>
</ul>
</div>
<?php endif; ?>
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.