PHP: Get File Size

There are 2 ways to the size of a file with PHP.

  1. PHP function filesize() returning the file size in bytes:
    $bytes = filesize('log.txt'); // $bytes now contains the size of the file log.txt in bytes
  2. PHP function stat() returning an array of information about the file including the size of it, also in bytes:
    $loginfo = stat('log.txt');
    echo $loginfo['size']; // output the size of the file in bytes

1 thought on “PHP: Get File Size”

Comments are closed.

Scroll to Top