..
The fread function is used to read the contents of a file previously opened using the function fopen .
The function takes two parameters: the file pointer and the length (in bytes) to read.
If we were to read only the first 100 bytes will:
<? Php
/ / Open file for reading
$ Myfile = fopen ('readme.txt', 'r');
/ / Read the first 100 bytes
fread ($ myfile, 100);
/ / Close the cursor
fclose ($ myfile);
?>
If, instead, I wanted to read the entire contents of the file I used:
<? Php
/ / Open file for reading
$ Myfile = fopen ('readme.txt', 'r');
/ / Stored in a variable length file
$ Bytes = filesize ('readme.txt');
/ / Read the file for the entire length
fread ($ myfile, $ bytes);
/ / Close
fclose ($ myfile);
?>
Note: If you simply want to extract the contents of a file you should use the function file_get_contents () .
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |