Support » Plugin: Links shortcode » [Plugin: Links shortcode] [TIP] Showing file size

  • This tip is for a very specific use of this plugin.
    Let’s say you’re using it to list files you’ve uploaded on wordpress media library and displaying links with Links Shortcode for download (PDFs, Docs, etc…).

    In this case, it’s good to show the user the size of the file the user is about to download. In order to do it you can do this (i’ve hacked the v1.1) of this plugin on WP 3.4.1:

    1- Open links-shortcode.php and after line 114, or after:
    $linkinfo['link_url'] = $bm->link_url;

    Paste this code:

    /**File size **/
    		/** remove http ***/
    		$url = substr($bm->link_url, 7);
    			/** revert url ***/
    		$url= strrev($url);
    			/** split everything in parts ***/
    		$partes = explode("/", $url);
    			/*** index the first 3 parts re-reverting ***/
    		$arquivo = "/".strrev($partes[2])."/".strrev($partes[1])."/".strrev($partes[0]);
    			/*** The upload directory **/
    		$uploads = wp_upload_dir();
    			/*** Compose the path ***/
    		$caminho = $uploads['basedir'].$arquivo;
    		$docsize = @filesize($caminho);
    		/*** size format is a built in WP function that shows the size in a nice format ***/
    		$linkinfo['link_size'] = '('.size_format($docsize).')';
    		/*** end**/

    2- Now on the configuration screen you can use the [link_size] tag to show the size of a file you uploaded and linked. I know it’s a very specific case but maybe it can help someone.

Viewing 1 replies (of 1 total)
  • Plugin Author Maarten Swemmer


    Hello ildario,

    This could be an interesting addition. I suspect however that filesize($caminho) is a server intensive function, since it has to access the file system on each pageview, or not, unless you use caching?

    Does it make sense to manually (or automatically) store the file size info in the Notes field and extract it from there? Perhaps in the format ‘<file size=”” />’? That would even pave the way for an infinite number of possible optional fields. Just brainstorming at this point.

    In any case to implement this in the plugin it would need to be something optional.

    Interested to learn your ideas on this.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Links shortcode] [TIP] Showing file size’ is closed to new replies.