Current Location: Home> Function Categories> fread

fread

Read files (safely used in binary files)
Name:fread
Category:File system
Programming Language:php
One-line Description:Read the open file.

Definition and usage

fread() function reads a file (safely used in binary files).

Example

Example 1

Read 10 bytes from the file:

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

Example 2

Read the entire file:

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

grammar

 fread ( file , length )
parameter describe
file Required. It is stipulated that the file should be read and opened.
length Required. Specifies the maximum number of bytes to be read.

illustrate

fread() reads up to length bytes from the file pointer file . This function stops reading the file when reading the maximum length bytes, or when reaching EOF, or (for network streams) when a packet is available, or (after opening the user space stream), or when 8192 bytes have been read, depending on which situation is encountered first.

Returns the read string, and returns false if an error occurs.

Similar Functions
Popular Articles