We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin Request: File Size Tag?

Development and Programming

lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

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.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
19 years ago
Robin Sowell's avatar Robin Sowell

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!

       
lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

Yes! A custom field would be even better! It’s just that I know how to manually type in the file size, but clients… They are confused creatures, at times. 😉 Anything that’s automatic would be good.

       
timj's avatar
timj
80 posts
19 years ago
timj's avatar timj

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.

       
lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

Actually, that’s what I meant. 😊 Anything so that whoever is downloading knows how big the file actually is.

       
ExpressionEngineer's avatar
ExpressionEngineer
148 posts
19 years ago
ExpressionEngineer's avatar ExpressionEngineer

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

       
PXLated's avatar
PXLated
1,800 posts
19 years ago
PXLated's avatar PXLated
give me a few minutes and I’ll hook you up with what timj described.

Am interested also :-)

       
ExpressionEngineer's avatar
ExpressionEngineer
148 posts
19 years ago
ExpressionEngineer's avatar ExpressionEngineer

Uhm.. I guess I’d better reply so everyone gets a ping from the forum module 😊

File attached along with some notes in my original post above.

:: andy

       
lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

Thanks so much! Works like a charm. :-D

       
lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

Oh, one more teeeeny request… Because I’m so demanding, heh… Is there a way to add a variable where it switches to MB after it’s past 1024 KB i.e. 1 MB? Thanks muchly!

       
timj's avatar
timj
80 posts
19 years ago
timj's avatar timj

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!

       
lealea's avatar
lealea
202 posts
19 years ago
lealea's avatar lealea

Timj: I made {filename} into an actual custom field that I typed the file’s name in it. Perhaps with {title} it’s looking for the Title of your post, as opposed to the name of the PDF?

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
19 years ago
Lisa Wess's avatar Lisa Wess

lealea is absolutely correct. You are best to rename that custom field to something other than {title} - if it is indeed a custom field?

       
timj's avatar
timj
80 posts
19 years ago
timj's avatar timj

Well, in this instance the {title} is the name of the file. This is a special weblog I’ve created to archive and index these pdfs.

       
PXLated's avatar
PXLated
1,800 posts
19 years ago
PXLated's avatar PXLated

Ehhh…thanks Andy!!!

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.