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: File Extension Icon

Development and Programming

Republic Factory's avatar
Republic Factory
5 posts
16 years ago
Republic Factory's avatar Republic Factory

Hi, decided to post my first official plugin here. It’s a small helper function that we’ve used in a couple of projects and found that it cleaned up the code a bit and saved us a couple of minutes in each project.

“File Extension Icon” returns an icon or the file type as text for a specific file, based on the file’s extension.

Usage

The plugin returns an icon (or the type as text) for a specific file based on the file extension (ie. .gif, .jpg, .pdf). The default parameters works great with the Silk icons by FamFamFam but you can customize the icons any way you want.

Basic usage:

{exp:file_ext_icon width="10" height="10"}http://www.somesite.com/some_file.jpg{/exp:file_ext_icon}

Returns:

/images/icons/jpg.png

Making use of the print_type parameter (to add CSS class in this case):

<li class="{exp:file_ext_icon print_type='yes'}/some_file.jpg{/exp:file_ext_icon}">Text</li>

Returns:

<li class="jpg">Text</li>

Parameters (examples):

  • widht: the icon image width in pixels (default is 16). (10)
  • height: the icon image height in pixels (default is empty) (10)
  • path: the path to the icon folder with trailing slash (default is ‘/images/icons/’). (path/to/file/)
  • ext: the extension of the icon files (default is ‘png’). (type)
  • class: the class of the image (default is empty). (className)
  • print_type: returns the extension of the file, ignoring all other parameters. (yes/no)

Download plugin:

http://republiclabs.com/expressionengine/file_ext_icon/

       
e-man's avatar
e-man
1,816 posts
16 years ago
e-man's avatar e-man

Sweet, used php for this a while ago but this can come in handy for future projects… don’t forget to submit this to devot-ee.com as well.

       
icebreaker's avatar
icebreaker
50 posts
16 years ago
icebreaker's avatar icebreaker

Nice functionality - helpful. However, I looked for jpeg.png among the famfam silk icons and did not find it there. I expect this means icons for all extensions must be pulled in from elsewhere/constructed first? Or – was I looking in the wrong place?

       
Christofer's avatar
Christofer
20 posts
16 years ago
Christofer's avatar Christofer

The default parameters works without parameters with the Silk icons as far as size (16x16px) and format (png), but you need to rename the icon files you wish to use.

All icons starting with “page_” are usually good for file extension icons and I know that many use the page_white_paint.png icon to represent jpeg’s. If you like it, just rename it to jpeg.png and you should be good to go.

       
icebreaker's avatar
icebreaker
50 posts
16 years ago
icebreaker's avatar icebreaker

OK - Thanks for the clarification.

       
ruraldreams's avatar
ruraldreams
279 posts
15 years ago
ruraldreams's avatar ruraldreams

This plugin is throwing errors with the latest build of EE - I had to disable gzip compression to get pages to show per this thread:

http://ellislab.com/forums/viewthread/129456/

Now it’s showing an error like this:

Warning: filesize() [function.filesize]: stat failed for /path/path/public_htmlhttp://domain.com/images/uploads/general/myfile.pdf in /path/path/public_html/system/plugins/pi.file_ext_icon.php on line 26

       
ruraldreams's avatar
ruraldreams
279 posts
15 years ago
ruraldreams's avatar ruraldreams

Disregard my message, I think now the error is a result of a modification to this plugin.

       
Christofer's avatar
Christofer
20 posts
15 years ago
Christofer's avatar Christofer

Ok, but let us know if you do think there are some problems with the plugin so we can fix it. Cheers!

       

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.