User Tools

Site Tools


uphp:functions:fread

This is an old revision of the document!


fread

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Return bytes from a file or stream

Description

mixed fread ( int $handle, int $bytes )

This function attempts to read a specified number of bytes from a file or stream. If less than the number of bytes are available it will return the available data. If no data is available it will return an empty string.

Parameters

$handle: Valid handle of a previously opened resource

$bytes: Limit to the number of bytes returned

Return Values

  • string containing the data requested from the resource
    • The length of the returned string depends on available data (0 to $bytes)
  • int 0 for error

Example

Read the 32 byte MD5 hash from file /md5.txt:

<?
  $fp=fopen("/md5.txt","r");
  if ($fp) {
    $data=fread($fp,32); // read 32 bytes from the file
    print($data);
    fclose($fp);
  } else {
    print("File open failed\n");
  }
?>

See Also

fgets() - Return a single line from a file or stream, with optional size limit

fwrite() - Write data to a file or stream

fsockopen() - Open an internet socket connection with optional timeout

fopen() - Open a file for reading or writing

f485open() - Open the RS-485 port at the specified baud rate and parity

fseropen() - Open the serial port at the specified baud rate with optional parameters

fclose() - Close a file, stream or socket

uphp/functions/fread.1490956506.txt.gz · Last modified: 2021/09/13 05:56 (external edit)