1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-15 03:05:26 +02:00

Update the PagefileExtra class to support some additional properties related to file size

This commit is contained in:
Ryan Cramer
2019-08-02 10:32:42 -04:00
parent 0e9cc868b7
commit d6c7273c63
2 changed files with 36 additions and 2 deletions

View File

@@ -16,7 +16,11 @@
* @property string $ext Alias of extension
* @property bool $exists Does the file exist?
* @property int $filesize Size of file in bytes
* @property string $filesizeStr Human readable size of file
* @property Pagefile|Pageimage $pagefile Source Pageimage object
* @property int $savings Bytes saved by this extra
* @property string $savingsStr Human readable savings by this extra
* @property string $savingsPct Percent savings by this extra
*
* The following properties affect the behavior of the URL-related methods
* =======================================================================
@@ -111,6 +115,16 @@ class PagefileExtra extends WireData {
return (int) @filesize($this->filename());
}
/**
* Return human readable file size string
*
* @return string
*
*/
public function filesizeStr() {
return wireBytesStr($this->filesize());
}
/**
* Return the full server disk path to the extra file, whether it exists or not
*
@@ -223,6 +237,20 @@ class PagefileExtra extends WireData {
case 'filesize':
$value = $this->filesize();
break;
case 'filesizeStr':
$value = $this->filesizeStr();
break;
case 'savings':
$value = $this->pagefile->filesize() - $this->filesize();
break;
case 'savingsStr':
$value = wireBytesStr($this->pagefile->filesize() - $this->filesize());
break;
case 'savingsPct':
$imageSize = $this->pagefile->filesize();
$extraSize = $this->filesize();
$value = round((($imageSize - $extraSize) / $imageSize) * 100) . '%';
break;
case 'url':
$value = $this->url();
break;