PHP
1. File specifies filename to read content
2. Length specifies number of bytes to read from file.
Syntax
PHP fread() function uses following syntax.
fread(file, length)
Example
Below is the two examples of reading content from file using php script.
First example will read first 20 bytes from file.
<?php $fn = fopen("myfile.txt","r"); $result = fread($fn, 20); echo $result; fclose($fn); ?>
Use this example to read all content from file. In this we used filesize() function to calculate size of file and passed it as argument for length.
<?php $fn = fopen("myfile.txt","r"); $result = fread($fn, filesize($fn)); echo $result; fclose($fn); ?>