Support

Account

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 ?>