Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP fread() Function

PHP fread() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The fread() function reads from an open file.

The function stops when it reaches the specified length or the end of file (EOF), whichever comes first.

Returns the read string, or FALSE on failure.

Syntax


string fread ( resource $handle , int $length )
Parameters Description
handle A file system pointer, typically a resource created by fopen().
length Required. Specifies the maximum number of bytes to read.

Tips and Notes

**Tip:** This function is binary-safe (meaning both binary data, such as images, and character data can be written with this function).


Example 1

Read 10 bytes from a file:


Example 2

Read the entire file:


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual