What is the filesize() function in PHP?

The filzesize() function is a built-in function in PHP.

The following is the function prototype:

filesize(filename)

Functionality

The filesize() function obtains the size of a file in bytes. The name of the file in question is passed as the input argument to the function.

Parameters and return value

The filesize() function takes the following input parameters:

  • filename: A string that represents the name of the file.

The function returns the size of the file in bytes in case of successful execution. The function returns False in case of failure.

Code

main.php
Edpresso.txt
<?php
echo "File size: ";
echo filesize("Edpresso.txt");
?>

Here, we create a text file by the name Edpresso.txt.

This file is passed to the filesize() function and the size returned by the function is displayed.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved