PHP fread () function
Definition and Usage
fread () function reads the file opened.
Function at specified length or read the end of the file (EOF) (whichever comes first), stop running.
This function returns the string read, if it fails it returns FALSE.
grammar
fread(file,length)
参数 | 描述 |
---|---|
file | 必需。规定要读取的打开文件。 |
length | 必需。规定要读取的最大字节数。 |
Tips and Notes
Tip: This function is binary safe.(Meaning that the binary data (such as images) and character data can use this function to write.)
Example 1
10 bytes read from the file:
<?php
$file = fopen("test.txt","r");
fread($file,"10");
fclose($file);
?>
$file = fopen("test.txt","r");
fread($file,"10");
fclose($file);
?>
Example 2
Read the entire document:
<?php
$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>
$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>
Complete PHP Filesystem Reference Manual