Display file size and type on page or post with attachments

you can use within your page or post template and also replace $attachment_id with the ID of the attachment you want to display information for.

// Assuming $attachment_id contains the ID of the attachment
$attachment_metadata = wp_get_attachment_metadata($attachment_id);

if ($attachment_metadata) {
    // Get file size in bytes
    $file_size = filesize(get_attached_file($attachment_id));
    
    // Convert file size to human-readable format
    $file_size_human = size_format($file_size);
    
    // Get file type
    $file_type = $attachment_metadata['mime_type'];
    
    // Display file size and type
    echo '<p>File Size: ' . $file_size_human . '</p>';
    echo '<p>File Type: ' . $file_type . '</p>';
}

// Display attachment link
echo wp_get_attachment_link($attachment_id);