This is based on this discussion.
Basically, I think it would be nice to be able to automatically append the file size of something you just uploaded through the EE interface. Can any one help? Is this possible? Details in the thread I linked.
Personally, I’d probably prefer the size be entered into a custom field- so I’d probably go at it by modifying the upload to grab the file size and insert it in a field for display purposes. Which really wouldn’t be that hard aside from figuring out an interface that allows a painless way to map it to the proper field. Extensions would probably make this doable with no hacking involved.
Just seems cleaner to me than grabbing the file size on the fly.
But yea- it would be a nifty plugin in whatever format!
I’m more interested in a {filesize} tag for downloads–photos, PDFs, whatever–a plugin that would auto-read a given fileon the server and display its size so the site user could consider whether to download it. Parameters might control whether filesize is listed as KB, MB, whatever. I realize there’s some pretty simple PHP one could stick into a template to do just this, but a plugin would give sitewide utility and be more useful to site design than (no slight intended, but merely by way of example!) Pirate Speak. My guess is it would rank among the top ten plugins.
give me a few minutes and I’ll hook you up with what timj described.
edit: here you go 😊
Sample code: The file is {exp:filesizer filename="{filename}” upload_pref=”1” units=”kb” decimals=”2”}Kb in size.
Please note: Whatever is in {filename} it must be a valid filename located in the given upload preference lest bad things will happen. You can only feed the filename=”” param with a filename as it is appended to the server_path of the given upload preference. Also, make sure your upload preference’s server_path isnt relative.. cause that breaks the plugin..
:: andy
Andy, I am impressed you turned this around so quickly. Very cool. I am not able to get it to work, however; it reads zero. Here’s my tag:
{exp:filesizer filename="{title}.pdf” upload_pref=”3” units=”mb” decimals=”1”}
{title} refers to the name of the pdf, and I hope you can embed tags like this. upload_pref is set to the number of my PDF upload directory. Is this tag properly constructed?
I’ve rechecked my server_path info and it is correct. Not to look a gift horse in the mouth, but the plugin might be more flexible if 1) it didn’t require an absolute server_pathname and/or 2) you could enter in the url as part of the filename or in a {path=} tag. Maybe something to think about for v1.0.
Many thanks!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.