fread
fread reads up to length bytes from the file pointer referenced by stream. Reading stops as soon as one of the following conditions is met:
length bytes have been read
EOF (end of file) is reached
a packet becomes available or the socket timeout occurs (for network streams)
if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.
Parameters
- stream
-
A file system pointer resource that is typically created using fopen.
- length
-
Up to length number of bytes read.
Return Values
Returns the read string or false on failure.
Notes
Note:
If you just want to get the contents of a file into a string, use file_get_contents as it has much better performance than the code above.
Note:
Note that fread reads from the current position of the file pointer. Use ftell to find the current position of the pointer and rewind to rewind the pointer position.