APICHANGE: add getFileSize() function to DMSDocument

This commit is contained in:
Normann Lou 2012-08-01 14:42:31 +12:00
parent 5e448c8d7b
commit f933e1a335
2 changed files with 24 additions and 1 deletions

View File

@ -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';
}
}

View File

@ -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