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

watbe - October 9, 2008 - 20:38

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

miiimooo - October 10, 2008 - 13:14

Subscribe

#3

miiimooo - October 13, 2008 - 21:27
Status:active» fixed

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

watbe - October 10, 2008 - 18:32

Cheers, I'll try that out soon. Thanks a lot!

--project followup subject--

Anonymous (not verified) - October 27, 2008 - 21:36

Automatically closed -- issue fixed for two weeks with no activity.

#5

Anonymous (not verified) - October 27, 2008 - 21:44
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#6

J0nathan - November 13, 2009 - 21:50
Status:closed» active

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

cafuego - November 16, 2009 - 04:13

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.

AttachmentSize
304930-theme-filefield-size.patch 2.93 KB

#8

quicksketch - November 16, 2009 - 04:27

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

cafuego - November 16, 2009 - 23:51

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

quicksketch - November 17, 2009 - 00:22

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)

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

cafuego - November 18, 2009 - 05:56

Ooh, it does the size already? I better have another look, then :-)

 
 

Drupal is a registered trademark of Dries Buytaert.