Home  >  Article  >  Backend Development  >  How to use fread function

How to use fread function

藏色散人
藏色散人Original
2019-02-16 10:30:1818769browse

php fread() function is used to read files (safe for binary files).

How to use fread function

php fread() function Syntax

Function: Read files (safe for binary files).

Syntax:

fread(file,length)

Parameters:

file Required. Specifies that the file should be opened for reading.

length Required. Specifies the maximum number of bytes to read.

Explanation: The file pointer file can read up to length bytes. This function is called after reading up to length bytes, or when EOF is reached, or (for network streams) when a packet is available, or (after opening a user space stream) 8192 bytes have been read. Reading of the file will stop.

php fread() function example

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

This article is an introduction to the PHP fread function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use fread function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use fputs functionNext article:How to use fputs function