From f933e1a335fd0f7bbe474f7d69a21aaa48a102c4 Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Wed, 1 Aug 2012 14:42:31 +1200 Subject: [PATCH] APICHANGE: add getFileSize() function to DMSDocument --- code/DMSDocument.php | 20 +++++++++++++++++++- code/interface/DMSDocumentInterface.php | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index 0ee5e7a..cad0d08 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -483,7 +483,25 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { * Return the extension of the file associated with the document */ function getFileExt() { - return pathinfo($this->Filename, PATHINFO_EXTENSION); + return strtolower(pathinfo($this->Filename, PATHINFO_EXTENSION)); + } + + /** + * Return the size of the file associated with the document + */ + function getFileSize() { + return filesize($this->getFullPath()); + } + + function getFileSizeFormatted(){ + if($size = $this->getFileSize()){ + if($size < 1024) return $size . ' bytes'; + if($size < 1024*10) return (round($size/1024*10)/10). ' KB'; + if($size < 1024*1024) return round($size/1024) . ' KB'; + if($size < 1024*1024*10) return (round(($size/1024)/1024*10)/10) . ' MB'; + if($size < 1024*1024*1024) return round(($size/1024)/1024) . ' MB'; + return round($size/(1024*1024*1024)*10)/10 . ' GB'; + } } diff --git a/code/interface/DMSDocumentInterface.php b/code/interface/DMSDocumentInterface.php index 9916aec..752bc00 100644 --- a/code/interface/DMSDocumentInterface.php +++ b/code/interface/DMSDocumentInterface.php @@ -137,6 +137,11 @@ interface DMSDocumentInterface { */ function getFileExt(); + /** + * Return the size of the file associated with the document + */ + function getFileSize(); + /** * Takes a File object or a String (path to a file) and copies it into the DMS, replacing the original document file