PHP filesize() Function

Definition

The filesize() function returns the size of the specified file.

Syntax

PHP filesize() Function has the following syntax.

filesize(filename)

Parameter

ParameterIs RequiredDescription
filenameRequired.File to check

Return

This function returns the file size in bytes on success or FALSE on failure.

Note

The result of this function are cached. Use clearstatcache() to clear the cache.

Example

The filesize() function returns its filesize in bytes.

To use fread() to read in an entire file, we can use the following line:


<?PHP//  ww w.j  a  va2s  . c  o  m
      echo filesize("test.txt");
      
      $filename = "test.txt";
      $handle = fopen("data.zip", "r");
      $contents = fread($handle, filesize($filename));
?>

Each time you read in a byte, PHP advances the file pointer by one place.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions