fread
Read files (safely used in binary files)
fread()
function reads a file (safely used in binary files).
Read 10 bytes from the file:
<?php $file = fopen ( "test.txt" , "r" ) ; fread ( $file , "10" ) ; fclose ( $file ) ; ?>
Read the entire file:
<?php $file = fopen ( "test.txt" , "r" ) ; fread ( $file , filesize ( "test.txt" ) ) ; fclose ( $file ) ; ?>
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. |
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.