PHP filesize() Function
The PHP filesize() function returns the size for the given file.
Note: The results of this function are cached. Use clearstatcache() function to clear the cache.
Syntax
filesize(filename)
Parameters
filename |
Required. Specify the path to the file. |
Return Value
Returns the size of the file in bytes, or false (and generates an error of level E_WARNING) in case of an error.
Example:
Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the size of the given file.
<?php $file = 'test.txt'; //getting the size of the file $file echo "$file contains: ".filesize($file)." bytes\n"; ?>
The output of the above code will be:
test.txt contains: 48 bytes
❮ PHP Filesystem Reference