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
Parameter | Is Required | Description |
---|---|---|
filename | Required. | 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.