Closed (fixed)
Project:
FileField
Version:
6.x-3.x-dev
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
6 Sep 2008 at 22:55 UTC
Updated:
14 Jul 2012 at 23:19 UTC
Jump to comment: Most recent file
Comments
Comment #1
watbe commentedsubscribing,,.,
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
Comment #2
miiimoooSubscribe
Comment #3
miiimoooDid a little bit of code browsing and here is the solution: (put this in your theme's template.php)
Comment #4
watbe commentedCheers, I'll try that out soon. Thanks a lot!
Comment #5
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #6
j0nathan commentedHi,
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
Comment #7
cafuego commentedIt'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.
Comment #8
quicksketchcafuego, 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().
Comment #9
cafuego commentedWell, 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().
Comment #10
quicksketchIf 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.
Comment #11
cafuego commentedOoh, it does the size already? I better have another look, then :-)
Comment #12
FunkMonkey commentedIs 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.
Comment #13
cafuego commentedThe code from #3 should work fine, afaik.
Comment #14
quicksketchUse the solution in #3 to override your theme's output. We should use a new issue for creating a "File: Icon" Views field.
Comment #15
mudd commentedDoes 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).
Comment #17
drein commentedFor 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("
");
return '
. ' ' . format_size($file['filesize']) . '' .'
';
}
it's really a little contribute but hope helps anyway.