fread syntax
fread ( resource $handle , int $length ) : string
$handle: file system pointer, resource created by fopen().
$length: Read the byte length of the file.
Return value: A string of length $length.
1. Confirm the bytes to be read
//File path $filename="./exit.txt"; //Get file resources $file = fopen($filename,'r'); //When reading a binary file, you need to set the second parameter to 'rb' //Get file content $file_info=fread($file,10); //Print file content echo $file_info; //Close file resources fclose($file); ?>
2. Do not confirm the bytes that need to be read.
To get all the contents of a file, you need to use another function filesize() function to see the size of the file.
//File path $filename="./exit.txt"; //Get file resources $file = fopen($filename,'r'); //Get file size $file_size= filesize($filename); //Get file content $file_info=fread($file, $file_size); //Print file content echo $file_info; //Close file resources fclose($file); ?>
The above is how PHP uses fread() to operate bytes. I hope it will be helpful to everyone.