I am uploading files with ZIP extension to Wordpress media library. How can I print the size of these files in KB? I just want people to see how many KB the file to download is.
CodePudding user response:
The questions is incomplete, could you please tell us how are you planning on displaying the files to the users to download, if you are directly copy-pasting your link (which I am assuming).
One workaround could be to create a shortcode to calculate the filesize:
First we need to get local directory for the file on the URL (since normal PHP functions do not support files on a remote server) and in order to check size of a file outside of the local server you will need to have cURL enabled on your server.
THIS WILL NOT WORK ON FILES OUTSIDE OF THE LOCAL SERVER (i.e. outside of the domain)
You need to place both the snippets in your functions.php file in your theme editor.
To find the local directory from URL, we can use this function from
Output: