Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Display file size for attachment

Quote Reply
Display file size for attachment
Hi there,

Is it possible to make a global that will display the file size of an attachment? i.e. I am successfully uploading CAD files using a new file column but it would lovely to display the file size when displaying the link.

Cheers,

Piers
Quote Reply
Re: [Piers1] Display file size for attachment In reply to
Sure, use this globals:

get_file_size
Code:
sub {
my $size = $DB->table('Links_Files')->select ( [File_Size''], { ForeignColName => $_[1], ForeignColKey => $_[0] } )->fetchrow;
$size = $size / 131072;
return sprintf("%.2f", $size);
}

..then call with:

<%get_file_size($ID,"Attachment")%>

..replace "Attachment" with the name of your field.

Untested, but should work =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display file size for attachment In reply to
Hello Andy,

Fatal error.
Comes back with "panic: pp_iter at GT::Template::dump line 538"

Why are you causing it to panic? It's like a minister having its expenses examined.

Thanks for your help.

Cheers,

Piers
Quote Reply
Re: [Piers1] Display file size for attachment In reply to
Mmmm, I can't see any reason why it would do that :/

Quote:
Why are you causing it to panic? It's like a minister having its expenses examined.

LMAO!!!!

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display file size for attachment In reply to
Hey Andy,

I never got this to work. Would it be broken because the actuals files are not directly accessible from the web? I did this to stop people guessing the directory, but the attachment scripts still downloads them ok in Links.

I now have quite a few CAD files being downloaded and displaying the file size would be really helpful.

Cheers,

Piers
Quote Reply
Re: [Piers1] Display file size for attachment In reply to
Which global are you using? The one a few posts up?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display file size for attachment In reply to
Yes - I just tried it again, and get an exciting '500 Internal Server Error' on any pages where I try it.

Cheers,

Piers
Quote Reply
Re: [Piers1] Display file size for attachment In reply to
Do you have any error logs you can look at?

Otherwise, try changing it to a much simpler bit of code - with some debugging, so we can see whats going on.

Code:
sub {
my $size = $DB->table('Links_Files')->select ( [File_Size''], { ForeignColName => $_[1], ForeignColKey => $_[0] } )->fetchrow;
return "FOO, got size: $size, for ForeignColName => $_[1], ForeignColKey => $_[0] ";
# $size = $size / 131072;
# return sprintf("%.2f", $size);
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display file size for attachment In reply to
Follows is now working thanks to Andy;

Global named 'get_file_size'

Code:
sub {
my $size = $DB->table('Links_Files')->select ( ['File_Size'], { ForeignColName => $_[1], ForeignColKey => $_[0] } )->fetchrow;
$size = $size / 1048576;
return sprintf("%.2f", $size);
}
Add to 'Detailed' Template

Code:
File size: <%get_file_size($ID,'attachment_field_name')%>Mb

Change 'attachment_field_name' to the name of the field you wish to find the file size for.

Cheers,

Piers