The fread() function reads an open file.
The function will stop running when it reaches the specified length or reaches the end of file (EOF), whichever comes first.
This function returns the string read, or FALSE on failure.
string fread ( resource $handle , int $length )
parameter | describe |
---|---|
handle | A file system pointer is a resource typically created by fopen(). |
length | Required. Specifies the maximum number of bytes to read. |
Tip: This function is binary safe. (Meaning that both binary data (such as images) and character data can be written using this function.)
Read 10 bytes from the file:
<?php$file = fopen("test.txt","r");$contents = fread($file,"10");fclose($file);?>
Read the entire file:
<?php$file = fopen("test.txt","r");$contents = fread($file,filesize("test.txt"));fclose($file);?>