We're currently developing the website using Divi and toolset.
I have created a form for website users to be able to upload files. Once the user has uploaded files, these should be made downloadable for other users. At the moment, I have created a button called 'download now' which downloads each file. However, the file's information is not shown on the button such as the file name, size and type.
I know there is a way of showing this information however it required php code to create a shortcode. There are a few forums that explain how to do this which I have tried to follow but have failed to make it work.
Hello. Thank you for contacting the Toolset support.
Well - I updated the the password as it was available for all.
You should send me access details now. I have set the next reply to private which means only you and I have access to it.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
You want to display following things for which custom field?:
=> file name - OK
=> size (which size - file size?)
=> type - OK
Well - I've adjusted the custom shortcode as given under within your current theme's functions.php file:
add_shortcode( 'my_file_name', 'wpml_hard_link'); // Actually activate the shortcode
function wpml_hard_link($atts) {
global $post; // So we can get the post meta later on
$url = "{$atts['file_url']}";
$types = "wpcf-upload-file";
if ($types) { // if the types_field argument was provided
$urls = get_post_meta($post->ID,$types); // let's get the (potentially multiple) values
$content = ''; // Setting up a variable to hold the links so we can return it later
foreach ($urls as $fileurl) { // Let's iterate for each of the multiple values
$arr = explode('/',$fileurl); // Split it up so that we can just grab the end part, the filename
$filename = explode(".",end($arr));
$content .= '<a href="'.$fileurl.'">'.$filename[0].'</a>'; // Create the link and store it in the $content variable
$content .= ' Type: '.strtoupper($filename[1]);
$headers = get_headers($fileurl, TRUE);
$filesize = $headers['Content-Length'];
switch ($filesize) {
case $filesize < 1024:
$size = $filesize .' B'; break;
case $filesize < 1048576:
$size = round($filesize / 1024, 2) .' KiB'; break;
case $filesize < 1073741824:
$size = round($filesize / 1048576, 2) . ' MiB'; break;
case $filesize < 1099511627776:
$size = round($filesize / 1073741824, 2) . ' GiB'; break;
}
$content .= ' Size: '.$size;
$content .= '<br />';
}
return $content; // Return the content as the shortcode value
} else { // Else we didn't use the fields_type argument, we just needed one URL we provided explicitly
$arr = explode('/',$url); // So let's split that URL up so we can grab the end
return '<a href="'.$url.'">'.end($arr).'</a>'; // And return the resultant link
} // We're done!
}