Thanks Shane 🙂
1. Custom code snippet
-----> Go to Toolset Settings --> Custom Code --> Create New Snipped and enter below code
I modified the code into:
add_shortcode( 'show-file-size', 'show_file_size_func' );
function show_file_size_func( $atts ) {
extract( shortcode_atts( array('file_url' => '',), $atts ) );
//URL of the remote file that you want to get
//the file size of.
$remoteFile = $atts['file_url'];
//Get the header response for the file in question.
$headers = get_headers($remoteFile, 1);
//Convert the array keys to lower case for the sake
//of consistency.
$headers = array_change_key_case($headers);
//Set to -1 by default.
$fileSize = -1;
//Check to see if the content-length key actually exists in
//the array before attempting to access it.
if(isset($headers['content-length'])){
$fileSize = $headers['content-length'];
}
var_dump($fileSize);
//Convert it into KB
$fileSizeKB = round($fileSize / 1024);
return 'Download • ' . $fileSizeKB . ' KB';
}
It works fine thanks to your suggestions Shane 🙂
As you can see in the pictures, it doesn't output the exact size, but I am fine with it...
<b>May I ask out of curiosity, where deviation can stem from ?</b>
2. Register Shortcode "show-file-size"
-----> Go to Toolset Settings --> Front-end Content ---> Third-party shortcode arguments --> Enter show-file-size in the field "Shortcode name" and click add
3. Use below shortcode in a View or Content Template
a) For Repeating Custom Fields with the following setup ....
<ul class="cu_pferdejornal_bilder">
[wpv-for-each field="wpcf-rask-bilder"]
<li>
[types field='rask-bilder' title='%%TITLE%%' alt='%%ALT%%' style='width: 100% !important; height: auto !important;'][/types]
<a href="[types field='rask-bilder' link='true' output='raw'][/types]" target="_blank" rel="noopener noreferrer">[show-file-size file_url="[types field='rask-bilder' output='raw' link='true'][/types]"]</a>
[/wpv-for-each]
</ul>
Replace rask-bilder with our own field-slug. You can find the field-slug in Toolset Custom Fields...
with CSS:
----> Enter in the View / Content Template CSS section:
/*Remove the Bullet Point, when you output the pictures*/
ul.cu_pferdejornal_bilder {
list-style-type: none !important;
margin: 0px !important;
padding: 0px !important;
}
b) For Single Custom Fields with the following setup ....
[types field='rask-bilder' title='%%TITLE%%' alt='%%ALT%%' style='width: 100% !important; height: auto !important;'][/types]
<a href="[types field='rask-bilder' link='true' output='raw'][/types]" target="_blank" rel="noopener noreferrer">[show-file-size file_url="[types field='rask-bilder' output='raw' link='true'][/types]"]</a>
Replace rask-bilder with our own field-slug. You can find the field-slug in Toolset Custom Fields...