PHP Tips & Tutorials

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

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Shoot me a message.

One reply on “PHP: Get File Size”

Comments are closed.