get file size

language: PHP
license: Other

Code for Snippet:

                
<?php
 
$size = filesize( get_attached_file( $attachment->ID ) );
 
?>
 
 
<?php $attachment_id = get_field('download');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
 
if (get_field('download')): ?>
<a href="<?php echo $url; ?>" ><?php echo $title; ?></a>
 
<?php 
$file_size = $attachment_id;								echo size_format($file_size, 2);									?>								
<?php endif; ?>
 
 
<?php $attachment_id = get_field('download');
$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);
 
// show custom field
if (get_field('download')): ?>
<a href=”<?php echo $url; ?>” ><?php echo $title; ?></a>
 
<!– show filesize –>
<?php echo $filesize; ?>
<?php endif; ?>
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 290
Date Added: 2016-08-15 14:44:14
Last Modified: 2016-08-15 08:44:28

Web Analytics