Download & Extend

To view file size and file description in view mode

Project:FileField
Version:6.x-3.x-dev
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

Comments

#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

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

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

--project followup subject--

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

#5

Status:fixed» closed (fixed)

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

#6

Status:closed (fixed)» 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 ANY file

#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.

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

#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

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

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

#12

Is there a solution that doesn't need Views? I am just displaying the uploaded files at the bottom of nodes.. no views to be found. Can I add the filesize to that? Or just use the code in #3? (or try the patch)

Thanks.

#13

The code from #3 should work fine, afaik.

#14

Category:feature request» support request
Status:active» fixed

Use the solution in #3 to override your theme's output. We should use a new issue for creating a "File: Icon" Views field.

#15

Does this code in #3 result in the size being shown twice in the edit form?
I tried patch in #7 and expected to get a second instance (leaving the #3 stuff in) but didn't. So tried removing the #3 stuff, but then no size shows in View and I get a single instance in edit form. (PS, I'm also using the other template.php hack to include the description as the file's link text, if applicable)

So, since the size is already shown (without any mods) in Edit but not in View, how do we adjust this so it just adds it to View? (seems to me the template.php hack adds it to all page types).

#16

Status:fixed» closed (fixed)

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

#17

For People that wants description and filesize, not filename, here is the snippet.
It's simply, remove the filename variable and replaced with ['data']['description']
I don't know anything about php,, this is only a copy/paste with several errors, but now it works.

<?php
/**
* Theme function for the 'generic' single file formatter. Added Filesize and description
*/
function phptemplate_filefield_file($file) {
$path = $file['filepath'];
$url = file_create_url($path);
$icon = theme('filefield_icon', $file);
//   drupal_set_message("".print_r($file,TRUE)."");
return ''. $icon . l($file['data']['description'], $url)
. ' ' . format_size($file['filesize']) . '' .'';
}

it's really a little contribute but hope helps anyway.

nobody click here