This concept is used to read and write the content in the file. If we want to read and write the file content first we should open that file with specific file mode. Different types of file modes are available.
r(read): By using this code we can read the contents of a file if we open a file name reboot by default a locates at the beginning file.
w(write): To write the contents (we can find arguments of file, arguments and file size) in the file first it deletes existing content and locate the file printer at the beginning of file if file is not available it creates new file.
a(append): To append new content with the existing content of file, file defaults the locates at the end of file file is not available it creates new file.
r+(read/write): To read write a contents of these files it is same as read mode.
w+(write/read): It is have at write mode, we can also read the contents.
a+:(append/read): It is same as append mode we can also read file content.
fopen: By using this function we can open that file, the specific file mode arguments are file name and file mode.
fread: To read the contents we can find arguments and file size.
fwrite: To write the contents in the file, arguments are file pointer and new content. At the time of writing a content in the file this function will over write by existing content.
fclose: To close a open file.
file size: To get current size occupied by a file.
rewind: This function locates file pointer and the beginning of file
- <?php
$fp= fopen(“myfile.txt”, “r”);
$size= filesize(“myfile.txt”);
$cont= fread($fp, $size);
echo $cont;
?> - <?php
$fp= fopen(“myfile.txt”, “w”);
fwrite($fp, “Alex”);
?> - <?php
$fp= fopen(“myfile.txt”, “a”);
fwrite($fp, “John”;
?> - <?php
$fp= fopen(“myfile.txt” ,”r+”);
fwrite($fp, “Smith”);
rewind($ftp);
echo fread($fp, file size(“myfile.txt”)
?>