To view file size and file description in view mode
faqing - September 6, 2008 - 22:55
| Project: | FileField |
| Version: | 6.x-3.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
I am using this module to manage my documents. The problem is that I can not view file size and file description, I can see the in edit mode only.
Can filefield module have an option to let people to see the file size and the description.
Thanks for the great module

#1
subscribing,,.,
I desperately need to be able to show the file size of uploads, is there a quick fix?
Applies for 5.x-2.3 as well
Cheers
Wayne
#2
Subscribe
#3
Did a little bit of code browsing and here is the solution: (put this in your theme's template.php)
<?php/**
* Theme function for the 'generic' single file formatter. Added Filesize
*/
function phptemplate_filefield_file($file) {
$path = $file['filepath'];
$url = file_create_url($path);
$icon = theme('filefield_icon', $file);
// drupal_set_message("<pre>".print_r($file,TRUE)."</pre>");
return '<div class="filefield-file clear-block">'. $icon . l($file['filename'], $url)
. ' <span="filefield file-size">' . format_size($file['filesize']) . '</span>' .'</div>';
}
?>
#4
Cheers, I'll try that out soon. Thanks a lot!
--project followup subject--
Automatically closed -- issue fixed for two weeks with no activity.
#5
Automatically closed -- issue fixed for two weeks with no activity.
#6
Hi,
With #3 modified, I encountered an "HTTP 0 Error" when uploading files.
See http://drupal.org/node/473760#comment-2262994
in #473760: HTTP 0 Error when Uploading ALL Files
#7
It'd be nice if the module had a theme_filefield_size hook built-in, so you could override and/or add in the file size without an additional hook_theme as well.
I've added this on a copy of filefield that I run (with some help from reply #3 above) and it seems to work fine. I can override the theme function to style the size string differently if I want/need to as well.
Patch attached.
#8
cafuego, Your patch makes the assumption that the filesize should always be shown by default. I don't see why overriding theme_filefield_size() would be any better than overriding theme_filefield_file().
#9
Well, it's kind of a first step on the way to providing additional formatter options to use in Views (icon only, size only etc)
I need a theme function for that anyway, so I just stuck that in. Not necessarily coz it's a good idea at all times, but it does what I need for the site I'm working on atm :-)
Would it perhaps be helpful if theme_filefield_file() an extra optional array parameter, which specifies which fields to output. That's could be helpful in that it saves users writing more code in their template.php; they could in theory just call theme('filefield_file', $file, $opts) instead of reimplementing all of theme_filefield_file().
#10
If Views formatting is what we're after, I think it would be preferable to add additional display options to Views when you join on the Files table through the FileField relationship. You can already output the filesize and mime type by making a relationship then using File: Filesize and File: Mime, I think it would make sense just to add "File: Icon" to the list of available fields when joining on the Files table.
#11
Ooh, it does the size already? I better have another look, then :-)