Piwik\Filesystem::getFileSize PHP Méthode

getFileSize() public static méthode

Get the size of a file in the specified unit.
public static getFileSize ( string $pathToFile, string $unit = 'B' ) : float | null
$pathToFile string
$unit string eg 'B' for Byte, 'KB', 'MB', 'GB', 'TB'.
Résultat float | null Returns null if file does not exist or the size of the file in the specified unit
    public static function getFileSize($pathToFile, $unit = 'B')
    {
        $unit = strtoupper($unit);
        $units = array('TB' => pow(1024, 4), 'GB' => pow(1024, 3), 'MB' => pow(1024, 2), 'KB' => 1024, 'B' => 1);
        if (!array_key_exists($unit, $units)) {
            throw new Exception('Invalid unit given');
        }
        if (!file_exists($pathToFile)) {
            return;
        }
        $filesize = filesize($pathToFile);
        $factor = $units[$unit];
        $converted = $filesize / $factor;
        return $converted;
    }

Usage Example

Exemple #1
0
 public function isAbnormal()
 {
     $size = Filesystem::getFileSize($this->tmpFile, 'MB');
     return $size !== null && $size >= 100;
 }
All Usage Examples Of Piwik\Filesystem::getFileSize