Filesystem::size PHP Method

size() public static method

public static size ( $file, $rewrite = true )
    public static function size($file, $rewrite = true)
    {
        if (!self::exists($file)) {
            return false;
        }
        $size = filesize(self::path($file));
        if ($rewrite) {
            foreach (self::$rewrite as $key => $value) {
                if ($size >= $value) {
                    return number_format($size / $value, 2) . ' ' . $key;
                }
            }
        } else {
            return $size;
        }
    }

Usage Example

Example #1
0
 /**
  * Set file size
  *
  * @return  mixed
  */
 public function setSize($size = NULL)
 {
     if (intval($size) > 0) {
         $this->set('size', $size);
     }
     if ($this->get('size')) {
         // Already set
         return $this->get('size');
     }
     // Get size for local
     if ($this->exists()) {
         $this->set('size', Filesystem::size($this->get('fullPath')));
     }
     // Formatted size
     if ($this->get('size')) {
         $this->set('formattedSize', \Hubzero\Utility\Number::formatBytes($this->get('size')));
     }
     return $this->get('size');
 }