Writing and Appending Content in a File : File Write « File Directory « PHP






Writing and Appending Content in a File

 <?php
  $myfile = "./test.txt";
  $openfile = fopen ($myfile,"w") or die ("Couldn't open the file");
  
  fwrite ($openfile,"This is a string \n");
  fclose ($openfile);
  
  $openfile = fopen ($myfile,"r") or die ("Couldn't open the file");
  $file_size=filesize($myfile);

  $file_contents = fread ($openfile,$file_size);
  $msg ="$file_contents";

  fclose ($openfile);
  echo $msg;
  ?>

           
       








Related examples in the same category

1.Write content to file
2.Writing and Appending to a File