mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-06-17 10:11:33 +02:00
APICHANGE: add getFileSize() function to DMSDocument
This commit is contained in:
parent
5e448c8d7b
commit
f933e1a335
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user