PHP filesize() Function
In this chapter you will learn:
- Definition for PHP filesize() Function
- Syntax for PHP filesize() Function
- Parameter for PHP filesize() Function
- Return for PHP filesize() Function
- Note for PHP filesize() Function
- Example - returns its filesize in bytes
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//from j ava 2 s . c om
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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP filetype() Function
- Syntax for PHP filetype() Function
- Parameter for PHP filetype() Function
- Return for PHP filetype() Function
- Note for PHP filesize() Function
- Example - returns the file type of a specified file or directory
Home » PHP Tutorial » PHP File Functions