File::size()

Gets the file sizes in human readable string format.

Table of Contents
  1. Description
  2. Example

Description

File::size(?string $unit = null, int $fix = 2, int $base = 1000): ?string;

This method returns the file size as a string of a number followed by a unit. If the file does not exist, this method returns null.

Example

$file = new File('.\path\to\file.txt');

$size = $file->size(); // Returns `'699 B'` (automatic, as short as possible)
$size = $file->size('KB'); // Returns `'0.7 KB'` (force unit to KB)
$size = $file->size(base: 1024); // Returns `'699 B'` (automatic, as short as possible using base of 1024)
$size = $file->size(base: 1024, unit: 'KiB'); // Returns `'0.68 KiB'` (force unit to KiB)

File::size()

Gets the file sizes in human readable string format.