Files & I/O
You will explain following function realeted to files:
- Opening a file
- Reading a file
- Writting a file
- Closing a file
fopen(filename, mode, include_path, context)
filename-Required specifies the file or url to open
mode-Required specifies the type of access you require to the file/stream.
Possible Values of mode
- "r"(read only)
- "w"(write only)
- "a"(Opens the file for writing only.
Places the file pointer at the end of the file.)
- "x"(write only)
Mode: Reading a text file
<?php $f=fopen("data.txt","r")or die ("unable to open file"); $r=fread($f, filesize("data.txt")); echo $r; fclose($f); ?>
Here is the text file display.
Mode: Writting a file
<?php $create =fopen("news.txt","w"); fwrite($create,"How are you"); fclose($create); ?>