PHP: Get File Size

by Yang Yang on April 22, 2009

Share This Article:
Subscribe to Kavoir: blog feed

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
Share This Article:
Subscribe to Kavoir: blog feed

You should also read:

{ 1 comment… read it below or add one }

Joe the Hosting Tech March 18, 2010 at 8:32 pm

anyone know a way to say “if file size is smaller than” a certain value, then perform a function?

Reply

Leave a Comment

Previous post:

Next post: