Read : Read data from file into a variable Write : Writing new file Append : Add more data at the end of file
useing.php ------------
| CODE | <?
include "file_func.php";
//create file write_file("test.txt","This is my initail text\n");
//add more data ot the existing file append_file("test.txt","New text added\n");
$data=read_file("test.txt");
echo "Data in file : <b>$data</b>"; ?>
|
Following file must be included wherever you wish to use following functions, and must be in the current folder.
file_func.php -----------------------
| CODE | <? //File will be rewritten if already exists function write_file($filename,$newdata) { $f=fopen($filename,"w"); fwrite($f,$newdata); fclose($f); }
function append_file($filename,$newdata) { $f=fopen($filename,"a"); fwrite($f,$newdata); fclose($f); }
function read_file($filename) { $f=fopen($filename,"r"); $data=fread($f,filesize($filename)); fclose($f); return $data; } ?>
|
|