PHP fread() Function

❮ PHP Filesystem Reference

Example

Read 10 bytes from an open file:

<?php
$file = fopen("test.txt","r");
fread($file,"10");
fclose($file);
?>
Run Example »

Definition and Usage

The fread() reads from an open file.

The function will stop at the end of the file or when it reaches the specified length, whichever comes first.

Syntax

fread(file, length)

Parameter Values

Parameter Description
file Required. Specifies the open file to read from
length Required. Specifies the maximum number of bytes to read


Technical Details

Return Value: The read string, FALSE on failure
PHP Version: 4.0+
Binary Safe: Yes

More Examples

Example

Read entire file:

<?php
$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>
Run Example »

❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.