Home >Backend Development >PHP Tutorial >foxit reader 2.3 Tips on using php fread
Description
string fread ( int handle, int length )
fread() reads up to length bytes from the file pointer handle. 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. Will stop reading the file, depending on which condition is encountered first.
Returns the string read, or FALSE if an error occurs.
Copy the code The code is as follows:
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen( $filename, "r");
$contents = fread($handle, filesize ($filename));
fclose($handle);
?>
Copy code The code is as follows:
$filename = "c:\files\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize ($filename));
fclose($handle);
?>
Copy the code The code is as follows:
// For PHP 5 and above
$handle = fopen("http://www.example.com/", "rb" );
$contents = stream_get_contents($handle);
fclose($handle);
?>
$handle = fopen ("http://www.example.com/", "rb" );
$contents = "";
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
?>
The above introduces foxit reader 2.3's tips on using PHP fread, including the content of foxit reader 2.3. I hope it will be helpful to friends who are interested in PHP tutorials.