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