From a5666560550ec93c7e66c494d6226f1345c80a26 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 22 May 2002 04:40:30 +0000 Subject: [PATCH] Added "size" method. --- lib/WebGUI/Attachment.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/WebGUI/Attachment.pm b/lib/WebGUI/Attachment.pm index 9892879d9..8febd4b9f 100644 --- a/lib/WebGUI/Attachment.pm +++ b/lib/WebGUI/Attachment.pm @@ -46,6 +46,7 @@ use WebGUI::Utility; $attachment->getFilename; $attachment->getIcon; $attachment->getPath; + $attachment->getSize; $attachment->getThumbnail; $attachment->getType; $attachment->getURL; @@ -226,6 +227,30 @@ sub getPath { } +#------------------------------------------------------------------- + +=head2 getSize ( ) + + Returns the size of this file. + +=cut + +sub getSize { + my ($size); + my (@attributes) = stat($_[0]->{_node}->getPath.'/'.$_[0]->getFilename); + if ($attributes[7] > 1048576) { + $size = round($attributes[7]/1048576); + $size .= 'mb'; + } elsif ($attributes[7] > 1024) { + $size = round($attributes[7]/1024); + $size .= 'kb'; + } else { + $size = $attributes[7]."b"; + } + return $size; +} + + #------------------------------------------------------------------- =head2 getThumbnail ( )